0

I know that there is a system broadcast called android.intent.action.SCREEN_OFF, but I want to receive broadcast when user lock his phone not screen off.

I am developing an application that can tell user how long his phones is locked.

1 Answers1

0

I don't see the broadcast you're asking for in the list of available broadcasts listed here https://developer.android.com/about/versions/11/reference/broadcast-intents-30). However, you could use the ACTION_SCREEN_OFF broadcast, and in its onReceive(), use one of the KeyguardManager class's methods to check if the device is locked. The method used would depend on your API version. For example, isKeyguardSecure() supports API 16 and above.

  • It's a great idea, but I found a better one. Every time received screen_off , check whether it is the first time after user_present – kevin zhang Jan 01 '22 at 11:39