Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to detect when the screen turns on by the user (Android)?

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

like image 738
Alex Kapustian Avatar asked Nov 23 '13 16:11

Alex Kapustian


1 Answers

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.

like image 94
Steve Benett Avatar answered Oct 12 '22 10:10

Steve Benett