Android开机自启APK应用
16lz
2021-01-23
当Android启动时,会发出一个系统广播,内容为ACTION_BOOT_COMPLETED,它的字符串常量表示为android.intent.action.BOOT_COMPLETED。只要在程序中“捕捉”到这个消息,再启动就OK。
code:
接收广播消息:BootBroadcastReceiver.java
package com.demo.BootStartDemo; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class BootBroadcastReceiver extends BroadcastReceiver { static final String ACTION = "android.intent.action.BOOT_COMPLETED"; @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION)){ Intent mIntent=new Intent(context,"启动类"); sayHelloIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(mIntent); } } }
在你的清单文件中配置:
该类派生自BroadcastReceiver,覆载方法onReceive中,检测接收到的Intent是否符合BOOT_COMPLETED,如果符合,则启动“想要启动”那个Activity。
权限:
更多相关文章
- Android项目中如果json字符串中key-value顺序很重要,不要使用Andr
- listview为空时,显示字符串
- android 字符串、颜色和尺寸
- Android DataBinding 字符串拼接
- Android xliff和字符串资源
- android xliff字符串操作
- Android Base64字符串转换成图片
- Android Wifi模块相关常量定义.
- Android Studio如何轻松整理字符串到string.xml中