Reprint Please specify source: http://blog.csdn.net/l1028386804/article/details/47028535
In this article, mainly through the monitoring of the start-up broadcast to monitor the status of the mobile phone operation, in Android can be broadcast mechanism to listen to some system services and system-level operations, well, not to say, directly on the code bar
1. Create a broadcast receiver class Bootcompletereceiver
The callback method in this class is automatically called after the phone is turned on, I just print out the relevant logs here, the specific business logic can be their own according to their specific needs to achieve.
The code is as follows:
Package Cn.lyz.mobilesafe.receiver;import Android.content.broadcastreceiver;import Android.content.context;import Android.content.intent;import android.util.log;/** * Register for Start-up broadcast * @author Liuyazhuang * */public class Bootcompletereceiver E Xtends broadcastreceiver {@Overridepublic void OnReceive (context context, Intent Intent) {log.i ("Bootcompletereceiver") , "You have heard the phone boot event");}}
2. Register the broadcast in the Androidmanifest.xml
The implementation is as follows:
<!--Register to start broadcasting-- <receiver android:name= "Cn.lyz.mobilesafe.receiver.BootCompleteReceiver" > <intent-filter<span style= "color: #FF0000;" > android:priority= "+" </span>> <span style= "color: #FF0000;" > <action android:name= "Android.intent.action.BOOT_COMPLETED"/></span> </intent-filter> </receiver>
All right, it's done.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android--Monitor phone boot events