How to realize Boot self-start in Android
Most people do not understand the knowledge points of this article "how to achieve boot self-startup in Android", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to achieve boot self-startup in Android" article.
1. Define a BroadcastReceiver
Java code
Public class BootReceiver extends BroadcastReceiver {public void onReceive (Context ctx, Intent intent) {Log.d ("BootReceiver", "system boot completed"); / / start activity String action= "android.intent.action.MAIN"; String category= "android.intent.category.LAUNCHER"; Intent myi=new Intent (ctx,CustomDialog.class); myi.setAction (action); myi.addCategory (category); myi.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity (myi) / / start service Intent s=new Intent (ctx,MyService.class); ctx.startService (s);}} public class BootReceiver extends BroadcastReceiver {public void onReceive (Context ctx, Intent intent) {Log.d ("BootReceiver", "system boot completed"); / / start activity String action= "android.intent.action.MAIN"; String category= "android.intent.category.LAUNCHER"; Intent myi=new Intent (ctx,CustomDialog.class); myi.setAction (action); myi.addCategory (category) Myi.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity (myi); / / start service Intent s=new Intent (ctx,MyService.class); ctx.startService (s);}}
two。 Configure permission for Receiver to receive system startup messages, in AndroidManifest.xml:
Xml code
< uses-permission android:name= "android.permission.RECEIVE_BOOT_COMPLETED"/> < uses-permission android:name= "android.permission.RECEIVE_BOOT_COMPLETED"/>3. Configure Receiver to receive system startup messages in AndroidManifest.xml
Android boot self-boot Xml code
< receiver android:name=".app.BootReceiver"> < intent-filter> < action android:name="android.intent.action.BOOT_COMPLETED"/> < category android:name="android.intent.category.HOME" /> < /intent-filter> < /receiver> < receiver android:name=".app.BootReceiver"> < intent-filter> < action android:name="android.intent.action.BOOT_COMPLETED"/> < category android:name="android.intent.category.HOME" /> < /intent-filter> < /receiver>The above is about the content of this article on "how to achieve boot self-startup in Android". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.