Android -- What happens when device is unlocked?
Asked Answered
H

2

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?

Halette answered 11/8, 2010 at 21:6 Comment(0)
B
56

Check out ACTION_USER_PRESENT.

Botchy answered 11/8, 2010 at 21:49 Comment(5)
Does anyone know what is fired if someone tries to unlock the phone but fails?Bolzano
@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.Botchy
@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.Quoin
@Botchy : 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?Enchorial
@Nikhil: Sorry, I do not know of one, but I have not looked into this in a long time.Botchy
F
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.

Formerly answered 18/3, 2017 at 10:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.