简体   繁体   English

Android开发人员选项->保持清醒== FLAG_KEEP_SCREEN_ON或WAKE_LOCK?

[英]Is Android Developer Options -> Stay Awake == FLAG_KEEP_SCREEN_ON or WAKE_LOCK?

I am building an app on an Android Nexus 10 tablet and it will serve as a kiosk, so I would like the screen to be on 100% of the time. 我正在Android Nexus 10平板电脑上构建应用程序,它将用作信息亭,因此我希望屏幕可以100%处于打开状态。 I've been currently using Developer Options > Stay Awake (screen will ever sleep while charging). 我目前一直在使用“开发人员选项”>“保持唤醒状态”(充电时屏幕将永远休眠)。

Per this documentation: https://developer.android.com/training/scheduling/wakelock 根据此文档: https : //developer.android.com/training/scheduling/wakelock

When this setting is enabled, is it equivalent to WAKE_LOCK or merely FLAG_KEEP_SCREEN_ON? 启用此设置后,它等于WAKE_LOCK还是仅仅是FLAG_KEEP_SCREEN_ON?

Thanks! 谢谢!

No, it's more low-level than that. 不,它比这更底层。 The "Stay Awake" toggle puts a value in Settings.Global, which is then read by the PowerManagerService. “保持唤醒”切换将一个值放入Settings.Global中,然后由PowerManagerService读取。 That value is a combination of the different plug-types that could be charging the phone (the switch uses AC, USB and WIRELESS by default). 该值是可以为电话充电的不同插头类型的组合(默认情况下,交换机使用AC,USB和WIRELESS)。

If the stored value isn't 0 , and the device is plugged into one of the plug types specified by that value, the PowerManagerService just never sets the device to the ASLEEP state. 如果存储的值不为0 ,并且将设备插入该值指定的插头类型之一,则PowerManagerService永远不会将设备设置为ASLEEP状态。

It's similar to a wakelock, but it has its own special process. 它类似于唤醒锁,但有其特殊的过程。

StayAwakePreferenceController PowerManagerService StayAwakePreferenceController PowerManagerService


By the way, FLAG_KEEP_SCREEN_ON actually uses a wakelock behind the scenes. 顺便说一句,FLAG_KEEP_SCREEN_ON实际上在幕后使用了唤醒锁。 You just don't need to hold the WAKELOCK permission to use it. 您只需要保持WAKELOCK权限即可使用它。

You can see that here and here . 您可以在这里这里看到。


For a kiosk-type thing, you should probably use FLAG_KEEP_SCREEN_ON. 对于信息亭类型的商品,您可能应该使用FLAG_KEEP_SCREEN_ON。 This wakelock prevents the screen from dimming, while the "Stay Awake" toggle doesn't. 此唤醒锁可防止屏幕变暗,而“保持唤醒”切换不会。

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

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