Search code examples
androidkeyguardscreen-lock

Get "Screen lock" setting in Android programatically


Is there a way of getting the current setting for Settings-->Security-->Screen Lock? It is the setting that can be "None", "Slide", "PIN", etc. I am not interested in changing it, just knowing the current one.

I'm only interested in telling "None" from any of the others, so that would work too. I have seen that for API 23 they have added DevicePolicyManager.setKeyguardDisabled(). I am looking for the equivalent getter, ideally for API 14 onwards.


Solution

  • After a couple of days of research I have come up to the conclusion that there is no way of doing this. KeyguardManager methods cannot tell the difference between None and Slide. There is no way of querying this from Android settings either.

    The only way is to manually monitor Keyguard when the screen goes off and assume, after 30 minutes, that if it didn't show up it is because None is set. This is obviously not a good idea, but Android seems determined to not give much information about its locking preferences.