简体   繁体   English

禁用后,再次显示Android锁定屏幕(使用lock.disableKeyguard())

[英]Android lock screen show again after it has been disabled (using lock.disableKeyguard())

Hey Im writing a launcher, in which Im building my own custom lockscreen. 嘿,我正在编写启动器,在该启动器中,我可以构建自己的自定义锁屏。

the custom lockscreen is an activity which being launched whenever the screen is off (by listening to Intent.ACTION_SCREEN_OFF) 自定义锁定屏幕是一种在屏幕关闭时启动的活动(通过监听Intent.ACTION_SCREEN_OFF)

to disable android's lockscreen I use this code: 要禁用Android的锁屏,我使用以下代码:

KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();

It all works good, till some point, in which android's lockscreen is turned on again (like it has never beem disabled before). 在某种程度上,一切正常,直到再次打开android的锁屏(就像以前从未禁用过beem一样)。

It happens a lot on samsung galaxy 2 (but happens also on other phones). 它在三星银河2上经常发生(但在其他手机上也发生)。

What Im I doing wrong? 我在做什么错?

thanks! 谢谢!

have you enabled DevicePolicyMangnager? 您启用了DevicePolicyMangnager吗? if not that function won't work. 如果没有,该功能将无法正常工作。

this comes from the documentation : 这来自文档

Note: This call has no effect while any DevicePolicyManager is enabled that requires a password. 注意:启用任何需要密码的DevicePolicyManager时,此调用无效。

here is a tutorial about it. 是关于它的教程。 Anyway i think it's not what you are looking for cause anytime your app will do that the user will have to give a password to give you admin permissions. 无论如何,我认为这不是您要查找的原因,因为无论何时您的应用程序执行该操作,用户都必须输入密码才能授予您管理员权限。

in general there are no way to programmatically disable the KeyGuard ( if secure pin, password, pattern, face ) and the most you can do is to show an activity on top of it. 通常,无法以编程方式禁用KeyGuard(如果使用安全的密码,密码,图案,面部),并且您能做的最多就是在其上方显示一个活动。

Managed to solve it somehow by calling 通过致电设法解决了问题

 KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
 KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
 lock.disableKeyguard();

right before I start the lock screen activity 在我开始锁定屏幕活动之前

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM