而用户未激活屏幕变暗屏幕、变暗、用户、未激活

2023-09-04 11:44:43 作者:命如薄纸

我有一个应用程序,用在让说4小时,但仅每隔5分钟,用户需要进行输入或读取屏幕。把手机的睡眠和锁定屏幕是有点讨厌。所以,我有两个选择:

I have an app which is used for lets say 4 hours, but only every 5 minutes a user needs to make an input or read the screen. Putting the phone to sleep and locking the screen is a bit annoying. So I have two options:

getWindow()addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 不锁屏,但是屏幕始终是光明的,我想朦胧它,而没有任何活动。正是由于电池寿命,或没有这件事那么多了这4个小时?

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); which doesn't lock the screen but the screen is always bright, I would like to dim it while there is no activity. Just because of battery life span, or doesn't that matter that much for these 4 hours?

唤醒锁 SCREEN_DIM_WAKE_LOCK 这不还有我想要什么,但我被告知,而用上面的选项1。

a wake lock SCREEN_DIM_WAKE_LOCK which does as well what I want, but I was told rather to use option 1 above.

我能否达到想要不知何故没有唤醒锁?

Can I achieve the wanted somehow without a wake lock?

推荐答案

您可以使用:

WindowManager.LayoutParams lp = getWindow().getAttributes();  
lp.dimAmount=1.0f; 
getWindow().setAttributes(lp);  

变暗/当你想undim屏幕。

to dim/undim the screen when you want to.

lp.dimAmount = 1.0F 将完全昏暗的屏幕,但你可以在你的意志,其值从0设置(不昏暗的话)来1.0F。

lp.dimAmount=1.0f will dim the screen totally but you can set it at your will with values from 0 (no dim at all) to 1.0f.

您可以设置一个计时器5分钟不活动后打电话到这一点,然后打开屏幕回上的任何触摸事件或此类也许。

You can set a timer to call this after 5 minutes of inactivity and then turn the screen "back on" on any touch event or such maybe.