24

I am trying to understand the intents that get launched when the device is unlocked.

For eg: Say my activity is running, and I press the power button (screen off, to lock the phone). INTENT.ACTION_SCREEN_OFF is launched. The activity is paused and the screen goes blank.

Now, when I press the power button again (INTENT.SCREEN_ON gets launched), the activity's onResume method is called. But the device is not yet unlocked.

What happens when the device is unlocked? To put it simply, what is the intent's action and category?

Chris
  • 361
  • 1
  • 4
  • 9

2 Answers2

56

Check out ACTION_USER_PRESENT.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Does anyone know what is fired if someone tries to unlock the phone but fails? – megaSteve4 Jun 18 '12 at 17:56
  • 2
    @megaSteve4: If by "fails" you mean they entered a PIN or password wrong, if your app is using the device admin APIs, you can find out about that. However, nothing is broadcast to normal apps about this AFAIK. – CommonsWare Jun 18 '12 at 19:59
  • @CommonsWare, do you know why ACTION_USER_UNLOCKED doesn't work. I register in my activity not in manifest as requirement and target api 24. Never receive event until changing to ACTION_USER_PRESENT. Strange. – thanhbinh84 Jun 25 '17 at 03:47
  • @CommonsWare : ACTION_USER_PRESENT does not work in Chromebook, so I am unable to detect if Chromebook is unlocked or not, is there any other workaround for Chromebook? – Nikhil Apr 02 '21 at 12:51
  • @Nikhil: Sorry, I do not know of one, but I have not looked into this in a long time. – CommonsWare Apr 02 '21 at 12:52
2

Additionally to

ACTION_USER_PRESENT

Broadcast Action: Sent when the user is present after device wakes up (e.g when the keyguard is gone). (API Lvl 3)

Android SDK 24 added

ACTION_USER_UNLOCKED

Broadcast Action: Sent when the credential-encrypted private storage has become unlocked for the target user. This is only sent to registered receivers, not manifest receivers.

bmul
  • 390
  • 3
  • 7
Patrick
  • 33,984
  • 10
  • 106
  • 126