java - how to get if phone come back from sleep mode Android -


it possible receive if phone come sleep mode? need receiver. onscreenon or interactive check if screen on or off. need when screen come sleep mode. android. api 23 , up.

i don't know if understood correctly seems need broadcastreceiver

you have more info in this answer

for sake of completeness i'll add here:

add following manifest:

<receiver android:name=".userpresentbroadcastreceiver">   <intent-filter>     <action android:name="android.intent.action.user_present" />     <action android:name="android.intent.action.action_shutdown" />  </intent-filter> </receiver> 

handle actions:

import android.content.broadcastreceiver; import android.content.context; import android.content.intent;  public class userpresentbroadcastreceiver extends broadcastreceiver {      @override     public void onreceive(context arg0, intent intent) {          /*sent when user present after           * device wakes (e.g when keyguard gone)          * */         if(intent.getaction().equals(intent.action_user_present)){          }         /*device shutting down. broadcast when device           * being shut down (completely turned off, not sleeping)          * */         else if (intent.getaction().equals(intent.action_shutdown)) {          }     }  } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -