简体   繁体   English

在Android系统上使用FLAG_KEEP_SCREEN_ON

[英]Using FLAG_KEEP_SCREEN_ON across the Android system

The goal of my app is to keep the screen on across the whole Android system. 我的应用程序的目标是使整个Android系统上的屏幕保持打开状态。 Previously, I've used FULL_WAKE_LOCK for this and it allowed me to block dimming of the screen across the system. 以前,我为此使用FULL_WAKE_LOCK ,它使我能够阻止整个系统上的屏幕变暗。 However, since the API Level 17, it got deprecated: 但是,自API级别17开始,已弃用:

This constant was deprecated in API level 17. 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. 该常数在API级别17中已弃用。大多数应用程序应使用FLAG_KEEP_SCREEN_ON而不是这种类型的唤醒锁,因为当用户在应用程序之间移动时,平台将正确地对其进行管理,并且不需要特殊权限。

Official documentation recommends using FLAG_KEEP_SCREEN_ON , however it is possible to use it only for particular Activity . 官方文档建议使用FLAG_KEEP_SCREEN_ON ,但是也可以仅将其用于特定的Activity

I would still FULL_WAKE_LOCK , however I've found that it doesn't work now on some of the devices, like MediaPad Huawei x2, Redmi Note 3, etc. The way I'm currently using the PowerManager can be found on GitHub . 我仍然会使用FULL_WAKE_LOCK ,但是我发现它现在在某些设备上不起作用,例如MediaPad Huawei x2,Redmi Note 3等。我当前使用PowerManager方式可以在GitHub上找到 Is there any better way to do accomplish this task after API level 17 ? API level 17之后,还有什么更好的方法来完成此任务?

Starting with API 23 and its new Doze mode Wake Locks are ignored and they do not prevent the system from entering sleep. 从API 23及其新的打ze模式唤醒锁将被忽略,它们不会阻止系统进入睡眠状态。

You should experiment with maintaining a foreground service in parallel with the wake lock, theoretically that should prevent the device from entering sleep. 您应该尝试与唤醒锁并行维护前台服务,从理论上讲,这应该可以防止设备进入睡眠状态。

NOTE : the foreground Service has to call startForeground and show a non dismissable Notification 注意 :前台服务必须调用startForeground并显示不可撤销的通知

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

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