简体   繁体   English

以编程方式禁用/延迟Android锁定屏幕

[英]Disable/Delay Android Lock Screen Programmatically

I'd like to disable/delay the lock screen programmatically. 我想以编程方式disable/delay锁定屏幕。 In looking into this, KeyguardManager is depreciated/doesn't work consistently, FLAG_DISMISS_KEYGUARD is not an option because I want to do this in the background, I don't want to use WakeLock for battery reasons, Device Administration does not appear to be capable of this and, while SCREEN_OFF_TIMEOUT is available to control when the screen sleeps, I was unable to find a similar timeout for the screen lock. 在寻找到这一点, KeyguardManager折旧/不工作始终, FLAG_DISMISS_KEYGUARD因为我想这样做的背景是不是一种选择,我不想使用激活锁定电池的原因,设备管理似乎并不能够这一点,虽然SCREEN_OFF_TIMEOUT可用于控制屏幕何时休眠,但我无法找到屏幕锁定的类似超时。

What am I missing here? 我在这里错过了什么? Thanks. 谢谢。

try this, it will keep awake the screen/ display , as long as the activity is on top. 尝试这个,只要活动在顶部,它就会保持唤醒屏幕/显示。 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Also this does not require any permission in manifest. 此外,这不需要清单中的任何权限。

@nandeesh的答案正在运行,但已弃用 ,禁用锁屏使用标志:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

Did you try this? 你试过这个吗?

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

Add

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>

You can disable the keyguard using this. 您可以使用此功能禁用键盘锁。

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

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