title: Turn off/on android screen
body: <p>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:</p>
  
  <pre><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);
  </code></pre>
  
  <p>But then, when I try to turn the screen on again, it does not work with this code:</p>
  
  <pre><code>WindowManager.LayoutParams layoutParam = getWindow().getAttributes();
  layoutParam.screenBrightness = oldBrightness;
  layoutParam.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
  getWindow().setAttributes(layoutParam);
  </code></pre>
  
  <p>Any idea to solve that ?</p>
  
  <p>thanks</p>