Android boot broadcast and android Broadcast
Sometimes we often need a program to start up and run. At this time, we need to listen to the system boot broadcast, and then start our program.
Not to mention the Code directly:
Public class BootReceiver extends BroadcastReceiver {@ Overridepublic void onReceive (Context context, Intent intent) {LogUtil. I ("BootReceiver", "BootReceiver is onReceive"); // TestService. startService (context); // start the service here }}
The colleague needs to add the permission to receive the boot broadcast in AndroidManifest. xml.
<Uses-permission android: name = "android. permission. RECEIVE_BOOT_COMPLETED"/>
Register the broadcast in AndroidManifest. xml.
<Cycler android: name = "com. test. bootreceiver. bootReceiver "> <intent-filter> <action android: name =" android. intent. action. BOOT_COMPLETED "/> </intent-filter> </Cycler>
So the success is ~~~~~~~~~