Android检查是否设置了锁屏

编程入门 行业动态 更新时间:2024-10-24 22:17:44
本文介绍了Android检查是否设置了锁屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要检查锁屏是否确实具有Pin或更安全的东西(密码,指纹等).我无法检查是否有密码,密码或图案.

i need to check if the lockscreen does have a Pin or something more secure (Password, Fingerprint etc.). Im able to check if there is a Pin, Password or a Pattern.

KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); return keyguardManager.isKeyguardSecure();

我的问题是我无法检测到锁屏是图案"还是更低的图案.我试过了:

My Problem is that i cant detect if the lockscreen is a Pattern or something lower. I tried this:

int lockPatternEnable = Settings.Secure.getInt(cr, Settings.Secure.LOCK_PATTERN_ENABLED);

,但已弃用它,并向我抛出错误.我也尝试过这个:

but its deprecated and throws me an error. I also tried this:

long mode2 = Settings.Secure.getLong(contentResolver, "lockscreen.password_type");

,但这也以SecurityException结尾.

but this ends with an SecurityException too.

有什么方法可以检测锁屏是否有大头针(或更高),或者是否有锁定模式或更低的密码? KeyguardManager不适用于我:/

Is there any way to detect if the lockscreen does have a pin (or higher) or it does a lock pattern or something lower? The KeyguardManager is not useful for me in that way :/

感谢您的帮助! 谢谢!

Any Help is appreciated! Thanks!

/编辑

第一个错误是:

Caused by: java.lang.SecurityException: Settings.Secure.lock_pattern_autolock is deprecated and no longer accessible. See API documentation for potential replacements.

第二个异常是:W/System.err:android.provider.Settings $ SettingNotFoundException:lockscreen.password_type

The Exception for the second one is: W/System.err: android.provider.Settings$SettingNotFoundException: lockscreen.password_type

当您使用带有棉花糖或更高版本的设备( developer.android/reference/android/provider/Settings.Secure.html )

The Error just appears when youre using devices with Marshmallow or later (developer.android/reference/android/provider/Settings.Secure.html)

推荐答案

我正在这样做: (灵感来自 gist.github/doridori/54c32c66ef4f4e34300f )

I'm doing this : (inspired from gist.github/doridori/54c32c66ef4f4e34300f)

public boolean isDeviceScreenLocked() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return isDeviceLocked(); } else { return isPatternSet() || isPassOrPinSet(); } } /** * @return true if pattern set, false if not (or if an issue when checking) */ private boolean isPatternSet() { ContentResolver cr = context.getContentResolver(); try { int lockPatternEnable = Settings.Secure.getInt(cr, Settings.Secure.LOCK_PATTERN_ENABLED); return lockPatternEnable == 1; } catch (Settings.SettingNotFoundException e) { return false; } } /** * @return true if pass or pin set */ private boolean isPassOrPinSet() { KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); //api 16+ return keyguardManager.isKeyguardSecure(); } /** * @return true if pass or pin or pattern locks screen */ @TargetApi(23) private boolean isDeviceLocked() { KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); //api 23+ return keyguardManager.isDeviceSecure(); }

更多推荐

Android检查是否设置了锁屏

本文发布于:2023-11-27 10:27:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637699.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!