tags:

views:

26

answers:

1

I developed a android appli. It's a widget. and I wanna get information whether the display locked or not. How can I do?

+2  A: 
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);

boolean isDisplayLocked = keyguardManager.inKeyguardRestrictedInputMode();

if (isDisplayLocked) {

  //your code

}
droid_fan
Btw, looping this code in a widget will kill your battery life. The only intents you can listen to are screen on/off.
Falmarri
@Falmarri: actually, for screen lock, `ACTION_USER_PRESENT` is better than `ACTION_SCREEN_ON` -- the latter should fire just when the screen lights up, but the former should fire when the user dismisses the lock. Also, none of these `Intents` can be listened to by manifest-registered `BroadcastReceivers` and so are unsuitable for use by an app widget.
CommonsWare