我正在尝试关闭 android 屏幕,然后在几秒钟后再次打开。“关闭”部分有效,使用以下代码:
WindowManager.LayoutParams layoutParam = getWindow().getAttributes();
oldBrightness = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS)/255f;
layoutParam.screenBrightness = 0;
layoutParam.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(layoutParam);
但是,当我尝试再次打开屏幕时,它不适用于以下代码:
WindowManager.LayoutParams layoutParam = getWindow().getAttributes();
layoutParam.screenBrightness = oldBrightness;
layoutParam.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(layoutParam);
有什么想法可以解决吗?
谢谢