What should I replace SCREEN_DIM_WAKE_LOCK with?

会有一股神秘感。 提交于 2019-11-30 01:22:41

问题


I am currently utilizing the below referenced code for a wake lock on an alarm notification activity. However, SCREEN_DIM_LOCK has been depreciated. 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");

回答1:


Android Developer documentation specifies that SCREEN_DIM_WAKE_LOCK should be replaced with 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.




回答2:


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.

This API should not have been deprecated - it is still needed in some cases, such as the "dim" case.

See also this.




回答3:


Just use

WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON

In place of

PowerManager.SCREEN_DIM_WAKE_LOCK


来源:https://stackoverflow.com/questions/22447533/what-should-i-replace-screen-dim-wake-lock-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!