android - 通过服务保持屏幕开启

标签 android service timeout screen wakelock

我想知道如何通过服务使屏幕永久打开。这是代码的场景: 用户将手机插入电源 socket , 广播接收器获取事件,启动防止屏幕超时的服务。 用户拔掉电话,服务被终止,超时恢复。

我想使用唤醒锁,但所需的级别在 API 13 中已弃用:

int SCREEN_BRIGHT_WAKE_LOCK This constant was deprecated in API level 13. Most applications should use FLAG_KEEP_SCREEN_ON instead of this type of wake lock, as it will be correctly managed by the platform as the user moves between applications and doesn't require a special permission.

FLAG_KEEP_SCREEN_ON 不能从我读过的服务中使用。

我不想修改屏幕超时数字,因为如果我的服务被破坏或应用程序被卸载,我不希望超时停留在一个很高的数字上。

此外,我的应用程序无法获得任何系统权限,因此任何需要DEVICE_POWER 权限的东西,我都无法使用

有什么想法吗? 感谢您的任何见解, 阿米什人

最佳答案

弃用并不意味着您不能在 13 以上的版本中使用它。 如果您的最低要求版本是 8(未确认),则您别无选择。唤醒锁在 API 级别 17 中仍然可用。

关于android - 通过服务保持屏幕开启,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15992632/

相关文章:

android - Android 2.3 中崩溃的服务重启后不调用 onStartCommand()

mobile - 跨手机后台服务

php - $.ajax 无法处理 php 脚本中的错误

JavaScript 使用 fetch 检查资源是否可访问,并设置超时

concurrency - Go 超时 sleep 但不忙等待

android - 在 android 中使用 key 和指数进行 RSA 加密

android - 无法获取 'https://jitpack.io/com/google/android/gms/play-services-basement/maven-metadata.xml'。从服务器 : Forbidden 收到状态代码 403

android - 获取未读邮件数gmail

android - 如何在opencv中循环检测眼瞳

android widget 和 localservice 绑定(bind)