set Screen Brightness Mode - Android User Interface

Android examples for User Interface:Screen Brightness

Description

set Screen Brightness Mode

Demo Code


//package com.java2s;

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);
        }/*from  w ww.  j  ava  2s . co m*/
        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