Screen lock screen and unlock monitor

Source: Internet
Author: User

The screen lock screen and the unlock will be sent two broadcast screen_on and Screen_off, but the two action can only be registered in the form of code to be listened to, registered in the Androidmanifest.xml is not listening.

 Public classScreenactionreceiverextendsBroadcastreceiver {PrivateString TAG = "Screenactionreceiver"; Private BooleanIsregisterreceiver =false; @Override Public voidOnReceive (Context context, Intent Intent) {String action=intent.getaction (); if(action.equals (intent.action_screen_on)) {LOGCAT.D (TAG,"Screen unlock broadcast ..."); } Else if(action.equals (intent.action_screen_off)) {LOGCAT.D (TAG,"Screen lock broadcast ..."); }    }     Public voidregisterscreenactionreceiver (Context mcontext) {if(!isregisterreceiver) {Isregisterreceiver=true; Intentfilter Filter=NewIntentfilter ();            Filter.addaction (intent.action_screen_off);            Filter.addaction (intent.action_screen_on); LOGCAT.D (TAG,"Registration screen unlock, lock broadcast receiver ..."); Mcontext.registerreceiver (screenactionreceiver. This, filter); }    }     Public voidunregisterscreenactionreceiver (Context mcontext) {if(isregisterreceiver) {Isregisterreceiver=false; LOGCAT.D (TAG,"Logout screen unlock, lock broadcast receiver ..."); Mcontext.unregisterreceiver (screenactionreceiver. This); }    }}

Screen lock screen and unlock monitor

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.