Android How to - Change Screen Brightness








Question

We would like to know how to change Screen Brightness.

Answer

/*from  ww w  .  jav a 2s .  c  o  m*/
import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;

class ActivityAttrUtils {
  public static void setScreenBrightness(final Activity mActivity,
      final float pScreenBrightness) {
    final Window window = mActivity.getWindow();
    final WindowManager.LayoutParams windowLayoutParams = window
        .getAttributes();
    windowLayoutParams.screenBrightness = pScreenBrightness;
    window.setAttributes(windowLayoutParams);
  }
}