set Screen Brightness - Android Phone

Android examples for Phone:Screen

Description

set Screen Brightness

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  ww  w.  j  a va  2  s.c  om*/
        } 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