1、Limiting application installation location
android:installLocation="internalOnly"
2、Add boot broadcast permission
3、Registered broadcast
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
4、Receive broadcast print log and start service
public class MyBootBroadCastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//
String action = intent.getAction();
Log.e("TAG", isOrderedBroadcast() + "action:" + action);
Intent service = new Intent(context, MyService.class);
context.startService(service);
}
}
Above for the realization of the code But android 4.4 and more than the phone after the start of the broadcast, the following can be.
Tried on 5.1, it can receive BOOT_COMPLETED broadcast. Think you need to remove this: android.intent.category.HOME.