set Window Brightness - Android android.provider

Android examples for android.provider:Settings

Description

set Window Brightness

Demo Code

import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;

public class Main {

  public static void setWindowBrightness(Activity activity, float screenBrightness) {
    float brightness = screenBrightness;
    if (screenBrightness < 1) {
      brightness = 1;/* w  w w.ja v  a2  s. c  om*/
    } else if (screenBrightness > 255) {
      brightness = screenBrightness % 255;
      if (brightness == 0) {
        brightness = 255;
      }
    }
    Window window = activity.getWindow();
    WindowManager.LayoutParams localLayoutParams = window.getAttributes();
    localLayoutParams.screenBrightness = (float) brightness / 255;
    window.setAttributes(localLayoutParams);
  }

}

Related Tutorials