3

i need to dismiss the default lock screen on some cases . it is possible using KeyguardManager.KeyguardLock , but it's deprecated and might not be available on the new android v4 version (ICS) . instead , here android docs i read that i should use "Use FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED "

so I've tried playing with them , but no matter what i try , after closing the activity that use those flags , i get back to the default lock screen , even if it's not the secure one . what is going on , and how should i fix it?

I've also read that there are some workarounds , by replacing the launcher application , but this is a weird fix , and requires the user's intervention , even though the application is not really a launcher application , and i'm not sure how i would

such a feature might even be used for replacing the lock screen with your own customized lock screen

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
android developer
  • 114,585
  • 152
  • 739
  • 1,270

2 Answers2

4

Check our issue 8778, which seems to be similar to what you are facing. The FLAG_DISMISS_KEYGUARD constant will ONLY work if you are using an Activity, it must not be PixelFormat.TRANSLUCENT, and it is forcing itself to be full screen, hiding system decoration like the status bar. The KeyguardManager API is deprecated, but it still works on Android 4.0 ICS and it is arguably your best bet at disabling the lock screen reliably and from any part of your code (even a background Service).

Tom
  • 6,947
  • 7
  • 46
  • 76
  • Look at this question: http://stackoverflow.com/questions/13052470/disabled-keyguard-lock-re-enables-itself-after-clicking-on-a-notification. it looks like the API didn't change but it already works different on API 13 and up – Muzikant Mar 07 '13 at 16:03
0

In case somebody needs Kotlin code that's up to date:

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
    val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
    keyguardManager.requestDismissKeyguard(this, null)
    setShowWhenLocked(true)
} else {
    window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)
}

And if you need a longer explanation on keyguard flags, check here.

lomza
  • 9,412
  • 15
  • 70
  • 85
  • 1
    Wait, what is the new condition for after Android O ? Would it work even when leaving the Activity? – android developer Jul 31 '22 at 09:16
  • the condition in IF is for Android O and after. It doesn't work when leaving the activity unfortunately, doesn't matter if keyguard is a secure or a non-secure one. – lomza Aug 02 '22 at 12:26
  • I see. So this doesn't help for what I asked on the question, because I wrote "after closing the activity that use those flags , i get back to the default lock screen". I wanted to dismiss the lock. Not to temporarily show some Activity that once you leave it, the lock screen appears. – android developer Aug 04 '22 at 07:21
  • there seems to be a bug on newer Android versions, not sure this is possible... – lomza Aug 05 '22 at 08:59
  • OK. The question is very old – android developer Aug 07 '22 at 06:56