(1) First add permission to start up permissions
<!--boot permissions-- <uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED"/>
(2) Register a broadcastreceiver to detect the start-up broadcast when the Android system is powered on
Package Com.wxyz.dengchaoqun.testswf;import Android.content.broadcastreceiver;import Android.content.Context; Import android.content.intent;/** * Created by Deng Chao on 2017/2/4. *///boot from start broadcast accept public class Autostartbroadcastreceiver extends Broadcastreceiver { static final String action_boot = " Android.intent.action.BOOT_COMPLETED "; @Override public void OnReceive (context context, Intent Intent) { if (intent.getaction (). Equals (Action_boot)) { Intent sayhellointent=new Intent (context,mainactivity.class); Sayhellointent.addflags (intent.flag_activity_new_task); Context.startactivity (sayhellointent);}}}
The emphasis here is that the boot can start the app activity can also start the service, which depends on the specific needs of the app, I am here to start the mainactivity
(3) Registering the service in the configuration file
<!--booting from the broadcast accept -<receiver android:name= ". Autostartbroadcastreceiver "> <intent-filter> <action android:name=" Android.intent.action.BOOT_COMPLETED "/> <category android:name=" Android.intent.category.HOME "/> </intent-filter> </receiver>
Android app start-up development