Question

I am using the following code to get the screen brightness.

    private static int getBrightness(Context context) {
    try {
        int brightness = Settings.System.getInt(context.getContentResolver(),
        Settings.System.SCREEN_BRIGHTNESS);
        return brightness;
    } catch (Exception e) {
    }
    return 0;
}

This code gives me the current brightness = 102 (which is correct). But I need to set the default brightness mode to 'auto'. How do I do that?

Was it helpful?

Solution

 Settings.System.putInt(cResolver,
         Settings.System.SCREEN_BRIGHTNESS_MODE,
         Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);

don't forget to apply permission

<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>

See Settings.System.SCREEN_BRIGHTNESS_MODE

OTHER TIPS

Settings.System.putInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, 1);

manual 0, auto 1

But it's more appropriate to use the constants as Ken suggested:)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top