android开机启动应用和服务

it2025-06-15  24

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

 

监听开机的广播接收器:

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"/>

 

 

 

转载于:https://www.cnblogs.com/bhlsheji/p/5105681.html

最新回复(0)