虽然是一个小改动,但尝试在末尾添加一个“F”,如下所示:
params.screenBrightness = 0F;
getWindow().setAttributes(params);
如果这不能解决问题,也许刷新屏幕可以通过将屏幕恢复到默认设置来工作。我做了一些研究,发现这段代码可能有助于刷新屏幕:
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
另外,您可以尝试使用 powermanager 唤醒锁打开手机:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
// Wakes the screen on.
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP, AudioControlExtender.this.getClass().getName());
wl.acquire();
如果这不起作用,请按照您现在的方式打开屏幕,然后执行以下操作:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
// Sets the screen on maximum brightness.
// This might fix the problem you are having with the screen brightness since
// the screen settings are changed.
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, AudioControlExtender.this.getClass().getName());
wl.acquire();