Android How to - Set screen brightness








Question

We would like to know how to set screen brightness.

Answer

// w  ww  .j av a2s .c o m
import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;
public class Main{

  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);
  }

}