There are situations that require Android programs to boot, that is, after the phone is powered up immediately after the corresponding Android program.
The way to do this is to accept the corresponding broadcast when the phone is powered on, and to accept the broadcast in the Android program.
1th Step: Build a custom broadcastreceiver class.
1 PackageCom.example.autostart;2 3 ImportAndroid.content.BroadcastReceiver;4 ImportAndroid.content.Context;5 Importandroid.content.Intent;6 ImportAndroid.widget.Toast;7 8 Public classBootupreceiverextendsBroadcastreceiver {9 Ten @Override One Public voidOnReceive (Context context, Intent Intent) { AToast.maketext (Context, "App started", Toast.length_long). Show (); - //---Start the main activity of our app--- - theIntent i =NewIntent (context, mainactivity.class); - i.addflags (intent.flag_activity_new_task); - context.startactivity (i); - } +}
2nd Step: Modify the Androidmanifest.xml file.
Add the right to receive a power-on broadcast.
1 <uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED"/>
Registers the custom Broadcastreceiver class.
1 <receiver android:name= ". Bootupreceiver ">2 <intent-filter>3 <action android:name=" Android.intent.action.BOOT _completed "/>45 <category android:name=" Android.intent.category.DEFAULT "/> </intent-filter></receiver>
This was basically done, and I was able to experiment on the computer's AVD. But on my phone on the boot has no effect, I also set the corresponding permissions in the mobile butler, but it is not successful. After I put the phone on the security software Uninstall, the program has been successful since the start, I analyzed the installation of the mobile phone butler after receiving the boot broadcast, the broadcast ended.