Detect if user is currently present without receiver for ACTION_USER_PRESENT and ACTION_SCREEN_OFF

346 views Asked by At

Is there a way to detect if the user is currently present without listening for the ACTION_USER_PRESENT-event and its counterpart ACTION_SCREEN_OFF?

I don't like to cache the last event in SharedPrefs, because I can't listen for ACTION_SCREEN_OFF using a receiver registered in the manifest. I want to avoid to implement a service that runs all the time just to get the ACTION_SCREEN_OFF-event. Because that service doesn't run anymore if my app crashes.

PowerManager#isScreenOn() or PowerManager#isInteractive() aren't an option since they return true if the user interacts with the lock screen.

Must support API level >=17.

0

There are 0 answers