Android--Monitor phone boot events

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.