Android 开机自启动
来源:互联网 发布:主域名 编辑:程序博客网 时间:2024/05/03 16:52
1. AndroidManifest.xml 权限设置
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
2.广播
public class BootReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { // boot //启动服务 或者 Activity Intent intent2 = new Intent(context, MainActivity.class);// intent2.setAction("android.intent.action.MAIN");// intent2.addCategory("android.intent.category.LAUNCHER"); intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent2); } }}
3.AndroidManifest.xml 注册广播
<receiver android:name=".reciver.BootReceiver" > <intent-filter android:priority="999"> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter></receiver>
4.完成以上步骤就可构建开机自启动APP(注意:若完成以上步骤,确认代码无误,但还是无法监听到广播,可能是由于手机默认静止了App开机自启动(例如:华为、小米等),此时去权限管理中,给该APP授权即可)。
0 0
- Android开机自启动
- Android开机自启动。
- 【Android】开机自启动
- 【Android】开机自启动 .
- Android开机自启动
- 【Android】开机自启动
- android开机自启动
- 【Android】开机自启动
- Android 开机自启动
- android 开机自启动
- android 开机自启动
- Android开机自启动
- 【Android】开机自启动
- Android开机自启动
- android开机自启动
- android开机自启动
- Android 开机自启动
- Android 开机自启动
- 定义一个加载数据的dialog
- 不为写博客而写博客
- 给出年月日判断是该年的第几天
- online_judge_1137
- Android 软键盘盖住输入框的问题
- Android 开机自启动
- Jenkins入门总结
- DrawerLayout使用一二事
- NSURLSession教程
- java为什么使用序列化
- Android Studio系列教程二--基本设置与运行
- Spark调度系列-----5.Spark task和Stage的跳过执行(ui显示task和stage skipped)
- 破坏
- 黑马程序员--反射的“魅力”