You can hear the wake of the screen today when you want the service of the application to run. Continue to learn the method of Baidu, together with the closure of monitoring closed also study together.
This situation requires dynamic registration of system broadcasts. Invalid in the actual run of static registration in Androidmanifest.xml.
Private Screenstatusreceiver Mscreenstatusreceiver;
Call the following function where needed:
Private void Registsreenstatusreceiver () { new screenstatusreceiver (); New Intentfilter (); Screenstatusif.addaction (intent.action_screen_on); Screenstatusif.addaction (Intent.action_screen_off); Registerreceiver (Mscreenstatusreceiver, screenstatusif); }
After the use is finished, log off:
Screenstatusreceiver class:
class screenstatusreceiver extends Broadcastreceiver {String screen_on =" Android.intent.action.SCREEN_O N "; String Screen_off = "Android.intent.action.SCREEN_OFF" ; @Override public void OnReceive (context context, Intent Intent) { if (Screen_on.equals (Intent.getaction ())) {LOG.W ("PPP", "ppp-screen lit"); else if (Screen_off.equals (Intent.getaction ())) {
LOG.W ("PPP", "ppp-screen is dimmed"); } } }
The Android monitor screen wakes up and shuts down the broadcast