set Screen Brightness Mode - Android android.provider

Android examples for android.provider:Settings

Description

set Screen Brightness Mode

Demo Code

import android.content.Context;
import android.provider.Settings;

public class Main {

  public static boolean setScreenBrightnessMode(Context context, boolean auto) {
    boolean result = true;
    if (isScreenBrightnessModeAuto(context) != auto) {
      result = Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE,
          auto ? Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC : Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
    }//  w  w w  .  j a  v a  2s . c  om
    return result;
  }

  public static boolean isScreenBrightnessModeAuto(Context context) {
    return getScreenBrightnessModeState(context) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC ? true : false;
  }

  public static int getScreenBrightnessModeState(Context context) {
    return Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE,
        Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
  }
}

Related Tutorials