I am trying to turn the android screen off and then on again, after a few seconds. The "turn off" part works, with this code:
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);
But then, when I try to turn the screen on again, it does not work with this code:
WindowManager.LayoutParams layoutParam = getWindow().getAttributes();
layoutParam.screenBrightness = oldBrightness;
layoutParam.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(layoutParam);
Any idea to solve that ?
thanks