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
2010-08-29 11:04:59
Btw, looping this code in a widget will kill your battery life. The only intents you can listen to are screen on/off.
Falmarri
2010-08-29 11:09:33
@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
2010-08-29 11:48:01