Android7.1.1开机自动启动配置
在AndroidManifest.xml文件中添加权限
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
在AndroidManifest.xml文件中注册接收广播配置, 添加到manifest > application节点下
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
开机启动执行代码
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
/**
* 接收开机广播
*/
public class MyReceiver extends BroadcastReceiver {
public MyReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
标签:app,public,content,自启,Intent,开机,import,Android,android From: https://www.cnblogs.com/Jinjunjie/p/18237736