Android设置APP开机自启动
程序员文章站
2022-03-18 10:58:52
文章目录设置APP开机自启一、设置注册监听广播
文章目录
设置APP开机自启
一、设置注册监听广播
<receiver android:name=".Ui.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
添加权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
2.新建广播类
代码如下(示例):
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Intent it = new Intent(context, BindEquipmentActivity.class);
it.setAction("android.intent.action.MAIN");
it.addCategory("android.intent.category.LAUNCHER");
it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(it);
}
}
}
总结
搞定!!!
本文地址:https://blog.csdn.net/github_38016668/article/details/109628182