Broadcastreceiver screen lock screen and unlock monitor

Source: Internet
Author: User

For unlocking and lock screen This use of the more frequent action, Google has made restrictions, must hand code registration

Directly on the code: This is a registered broadcast

1  Public classMainactivityextendsappcompatactivity {2 Screen screen ;3 @Override4     protected voidonCreate (Bundle savedinstancestate) {5         Super. OnCreate (savedinstancestate);6 Setcontentview (r.layout.activity_main);7 8Screen =NewScreen ();9Intentfilter filter =NewIntentfilter ();Ten         //Add Action OneFilter.addaction ("Android.intent.action.SCREEN_OFF"); AFilter.addaction ("Android.intent.action.SCREEN_ON"); -         //register a broadcast recipient -          This. Registerreceiver (screen,filter); the     } -  - @Override -     protected voidOnDestroy () { +         Super. OnDestroy (); - unregisterreceiver (screen); +}

1  Public classScreenextendsBroadcastreceiver {2 @Override3      Public voidOnReceive (Context context, Intent Intent) {4String action =intent.getaction ();5         if(Action.equals ("Android.intent.action.SCREEN_OFF")){6SYSTEM.OUT.PRINTLN ("Screen lock screen up");7}Else if(Action.equals ("Android.intent.action.SCREEN_ON")){8SYSTEM.OUT.PRINTLN ("Screen unlocked");9         }Ten     } One}

Broadcastreceiver 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.