title: changing screen brightness via android app
body: <p>I have the same need like <a href="https://stackoverflow.com/questions/7646865/changing-screen-brightness-programmatically-as-with-the-power-widget">this</a>, but I found the answer under that question aren't work.</p>
  
  <p>I want to make buttons to change my screen brightness while my app is running. </p>
  
  <p>I have found this code, but it doesn't work if I copy this code into my mainActivity directly.</p>
  
  <pre><code>WindowManager.LayoutParams lp = getWindow().getAttributes();
  float brightness=1.0f;
  lp.screenBrightness = brightness;
  getWindow().setAttributes(lp);
  </code></pre>
  
  <p><strong>I use android studio and API level is 21</strong>
  and I added user permission. </p>
  
  <p>This piece code is the nearest to my target, who can help me run this code?</p>