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