android程序开机自启
来源:互联网 发布:修复dll软件 编辑:程序博客网 时间:2024/06/06 05:18
原理是通过注册广播接收器接收开机广播,然后启动主界面。
1、首先新建一个MyReceiver类继承BroadcastReceiver来接收系统广播。
public class MyReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context arg0, Intent arg1) {// TODO Auto-generated method stub//Intent intent = new Intent(MainActivity.class);if(arg1.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){Intent intent=new Intent(arg0,MainActivity.class);//收到广播后启动主界面intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//设置启动类型arg0.startActivity(intent);}}}2、在资源文件中声明接收器
<!-- 声明接收器 --> <receiver android:name="com.example.testbootstart.MyReceiver"> <!-- 广播过滤 --> <intent-filter> <!-- 开机初始化完毕发送的广播,开机完成后发送并只发送一次 --> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
安装APK后,每次手机重启都会启动程序的MainActivity。
注意事项:可能需要在应用管理中设置允许开机自启动。
项目源码:https://github.com/CoderDog/TestBootStart
0 0
- android程序开机自启
- 程序开机自启
- Android开机自启动程序
- Android开机自启动程序
- Android 开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android 开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- android程序开机自启动
- Android开机自启
- Android 开机自启
- hadoop: Could not resolve hostname ***
- RTMP协议
- 统计工龄 模拟EXCEL排序 银行排队问题之单队列多窗口问题 银行业务队列简单模拟 堆栈操作合法性 两个有序序列的中位数
- 中国惠普前总裁孙振耀的毕生经验之谈
- Python Twisted
- android程序开机自启
- 键盘遮挡输入框的问题
- Saltstack数据系统-Pillar
- 几个框架的环境搭建
- 开始学习redis
- 51Nod-1102-面积最大的矩形
- Codeforces #187 (Div. 1) B. Sereja and Periods && Hihocoder 1355 (字符串匹配倍增好题)
- 实现Android的消息通知栏
- CentOS 7 Debian 8 安装VMware-tools