android开机启动应用和服务

注冊广播监听开机状态。启动应用和服务等;

 

监听开机的广播接收器:

public class BootCompletedReceiver extends BroadcastReceiver{
   

 @Override
 public void onReceive(Context context, Intent intent) {
        //开机启动服务
          Intent it= new Intent("com.test.action.testservice");
          context.startService(it);

           //启动应用

         Intent act= new Intent("com.test.action.testactivity");
          context.startActivity(act);

 }
 
}

在Manifest.xml中注冊监听开机的广播:

     <receiver android:name="com.test.BootCompletedReceiver">   
         <intent-filter>   
                 <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>     
        </receiver> 

 

加入开机状态的权限:

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

 

 

 

posted @ 2016-01-06 15:10  phlsheji  阅读(393)  评论(0编辑  收藏  举报