android开机自启动,service

来源:互联网 发布:酒店业数据 编辑:程序博客网 时间:2024/06/09 23:54
if(inta.getAction().equals("android.intent.action.BOOT_COMPLETED")){/*Intent startIntent = new Intent(arg0,MainActivity.class);startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); arg0.startActivity(startIntent); */Intent startIntent = new Intent(arg0,MQService.class);startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //启动新任务arg0.startService(startIntent);}


1.注册Reciever 接收Android开机消息 BootBroadcastReceiver

2.AndroidMainifest.xml中注册 

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>

注册Receiver接收器 

<receiver android:name="com.rabbitmq.mqforward.BootBroadcastReceiver" >
   <intent-filter>
   <action android:name="android.intent.action.BOOT_COMPLETED"/>
    <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.HOME" />
   <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
    </receiver>

<service android:name="com.rabbitmq.mqforward.MQService"></service>注册Service
0 0
原创粉丝点击