android开机自启动程序设置
来源:互联网 发布:python的全局变量 编辑:程序博客网 时间:2024/05/01 11:50
Android启动时,会发出一个系统广播 ACTION_BOOT_COMPLETED,它的字符串常量表示“android.intent.action.BOOT_COMPLETED”
开机自启动程序,只需要“捕捉”到这个消息再启动你的程序即可,我们要做的是接收这个消息,并实现一个BroadcastReceiver。
第一步 配置在AndroidManifest.xml中Application节点内,添加自定义的广播类:
- <receiver android:name=".MyBootReceiver" >
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </receiver>
第二步 定义程序主要Activity
- public class MainActivity extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- }
第三步 自定义广播类 MyBootReceiver
- public class MyBootReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
- Intent _intent = new Intent(context, MainActivity.class);
- _intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(_intent);
- }
- }
- }
0 0
- android开机自启动程序设置
- Android 程序开机自启动的设置
- 设置程序开机自启动
- Android开机自启动设置
- android 设置开机自启动
- Android开机自启动程序
- Android开机自启动程序
- Android 开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android 开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- 17周项目二,3,(指针做形参) . .
- API分页最佳实践
- Tomcat SSL配置及Tomcat CA证书安装
- C语言 指针出参使用方法
- Ubuntu 12.04安装Google Chrome
- android开机自启动程序设置
- 在Windows Server 2012下安装.net framework 3.5
- 11往10导
- Hibernate 自动创建表结构
- Android 自定义View(2) -- 绘图的基本知识
- 享受知识饕餮盛宴,尽在2014年课程
- [Qt] Qt实现HTTP请求 [2013-12-18更新]
- C#中窗体程序中的this.SuspendLayout()和this.ResumeLayout()
- Tomcat SSL配置 Connector attribute SSLCertificateFile must be defined when using SSL with APR解决