您的位置:首页 > 移动开发 > Android开发

android开机自启动,service

2016-04-29 17:44 399 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: