Android开机自启动可以通过定义一个BroadcastReceiver;配置Receiver的许可等方式来实现。在这里就对这些步骤进行一个详细介绍。
在模拟器中对Android 操作系统进行相应的编写,可以帮助我们实现应用程序的开机自启动功能。在这里我们就来通过一段代码充分的掌握Android开机自启动的相关实现方法,以帮助大家掌握这一应用。

1.定义一个BroadcastReceiver
public class BootReceiver extends BroadcastReceiver {public void onReceive(Context ctx, Intent intent) {Log.d("BootReceiver", "system boot completed");// start activityString action = "android.intent.action.MAIN";String category = "android.intent.category.LAUNCHER";Intent myi = new Intent(ctx, Welcome.class);myi.setAction(action);myi.addCategory(category);myi.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);ctx.startActivity(myi);// start serviceIntent s = new Intent(ctx, MyService.class);ctx.startService(s);}}


2.配置Receiver的许可,允许接收系统启动消息,在AndroidManifest.xml中:

<!-- 添加接收系统启动消息(用于开机启动)权限 --><uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>


3.配置Receiver,可以接收系统启动消息,在AndroidManifest.xml中
Android开机自启动的Xml代码

<!-- 开机启动 --><receiver android:name=".app.BootReceiver" android:enabled="true"><intent-filter><action android:name="android.intent.action.BOOT_COMPLETED"/><category android:name="android.intent.category.HOME" /></intent-filter>   </receiver>


4.启动模拟器,可以看到系统启动后,弹出一个对话框。
Android开机自启动的具体方法就为大家介绍到这里。

更多相关文章

  1. Android从Linux系统启动
  2. Android(安卓)启动应用程序方式
  3. android java代码的启动:app_process
  4. Android应用程序启动过程源代码分析(1)
  5. 使用Android(安卓)adb命令来启动Android应用程序
  6. Android热修复技术链接收集
  7. [转]Simple Guide for Porting Android(安卓)Kernel
  8. Android(安卓)启动过程
  9. Android(安卓)Launcher 分析

随机推荐

  1. HttpClient与HttpUrlConnection下载速度
  2. Android简明开发教程十七:Dialog 显示图像
  3. android实操--练习1
  4. android 对象传输及parcel机制
  5. 玩转Android之Activity详细剖析
  6. Phonegap Device 获取设备信息
  7. mac终端配置Android(安卓)ADB命令
  8. Ubuntu11.10下编译android源码4.0.3
  9. 为什么应用商店里搜索不到你的App?
  10. android中的事件类型分为按键事件和屏幕