It would be possible to receive if phone is come back from sleep mode? I need a receiver. OnScreenOn or interactive is to check if the screen is On or Off. But I need to get exactly when the screen come back from sleep mode. Android. API 23 and up.
Asked
Active
Viewed 694 times
0
-
Are der a wait to receive if phone is come back from sleep mode? I need a receiver. OnScreenOn or interactive is to check if the screen is On or Off. But I need to get exactly when the screen come back from sleep mode. Android. API 23 and up. – Alexander Hermann Jul 28 '17 at 10:42
-
what phone? ae you android? – ΦXocę 웃 Пepeúpa ツ Jul 28 '17 at 10:43
-
Samsung s6 edge Android 7.0-7.1.2 – Alexander Hermann Jul 28 '17 at 10:44
-
what about onResume? – Kevin Jul 28 '17 at 10:51
-
OnResume? Have I put it in a receiver? Activity? – Alexander Hermann Jul 28 '17 at 14:54
1 Answers
1
I don't know if I understood you correctly but it seems like you need a BroadcastReceiver
You have more info in this answer
For the sake of completeness I'll add it here:
Add the following to your 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 the 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 the user is present after
* device wakes up (e.g when the keyguard is gone)
* */
if(intent.getAction().equals(Intent.ACTION_USER_PRESENT)){
}
/*Device is shutting down. This is broadcast when the device
* is being shut down (completely turned off, not sleeping)
* */
else if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) {
}
}
}

Alberto S.
- 7,409
- 6
- 27
- 46
-
Hi but the problem is that it works just after the device is rebooted one time. – Alexander Hermann Jul 29 '17 at 20:10