set Screen Brightness against value 255 - Android User Interface

Android examples for User Interface:Screen Brightness

Description

set Screen Brightness against value 255

Demo Code


//package com.java2s;

import android.content.Context;

import android.provider.Settings;

public class Main {

    public static boolean setScreenBrightness(Context context,
            int screenBrightness) {
        int brightness = screenBrightness;
        if (screenBrightness < 1) {
            brightness = 1;/*from  w  ww .  j a  va 2 s.c  o m*/
        } else if (screenBrightness > 255) {
            brightness = screenBrightness % 255;
            if (brightness == 0) {
                brightness = 255;
            }
        }
        boolean result = Settings.System.putInt(
                context.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS, brightness);
        return result;
    }
}

Related Tutorials