简体   繁体   English

我应该用什么替换SCREEN_DIM_WAKE_LOCK?

[英]What should I replace SCREEN_DIM_WAKE_LOCK with?

I am currently utilizing the below referenced code for a wake lock on an alarm notification activity. 我目前正在使用以下引用的代码来对警报通知活动进行唤醒锁定。 However, SCREEN_DIM_LOCK has been depreciated. 但是, SCREEN_DIM_LOCK已折旧。 So, what should I be replacing it with? 那么,我应该用它替换它?

//Instance of wake lock for AlarmActivity
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "MyWakeLock");

Android Developer documentation specifies that SCREEN_DIM_WAKE_LOCK should be replaced with FLAG_KEEP_SCREEN_ON . Android开发者文档指定SCREEN_DIM_WAKE_LOCK应改为FLAG_KEEP_SCREEN_ON After doing a bit of digging, I turned up this... 经过一番挖掘后,我发现了这个......

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

It should be placed in the onCreate() method. 它应该放在onCreate()方法中。

It can be replaced for FLAG_KEEP_SCREEN_ON , as the javadoc says, but this will prevent the screen from dimming - it will remain bright. 正如javadoc所说,它可以替换为FLAG_KEEP_SCREEN_ON ,但这样可以防止屏幕变暗 - 它会保持亮度。

This API should not have been deprecated - it is still needed in some cases, such as the " dim " case. 这个API不应该被弃用 - 在某些情况下仍然需要它,例如“ 昏暗 ”的情况。

See also this . 另请参见

Just use 只是用

WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON

In place of 代替

PowerManager.SCREEN_DIM_WAKE_LOCK

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

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