I found post from two year ago that somebody said that it can't be done. I also found that I can use ACTION_USER_PRESENT to detect when a user unlock the screen, but can I detect when the user turns on the screen (by any action)?
EDIT: I want to know when the user press any button or do anything else that can turn on the screen
The system will broadcast Intent.ACTION_SCREEN_ON which you can use to catch the event when the screen turns on.
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
// your code here
}
}
}
Note that you can't broadcast this event yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With