How do I detect the screen brightness range on android?

Use this method to get max value for brightness

public int getMaxBrightness(Context context, int defaultValue){

    PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if(powerManager != null) {
        Field[] fields = powerManager.getClass().getDeclaredFields();
        for (Field field: fields) {

            //https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/os/PowerManager.java

            if(field.getName().equals("BRIGHTNESS_ON")) {
                field.setAccessible(true);
                try {
                    return (int) field.get(powerManager);
                } catch (IllegalAccessException e) {
                    return defaultValue;
                }
            }
        }
    }
    return defaultValue;
}

I have tested this on a couple of devices (mostly android 9, 10 devices, including some xiaomi devices, which usually set brightness higher than the usual 255), and looks like this is working.

Google does not promote accessing hidden fields/methods using reflection. Any android update could potentially break this solution.

Another possible solution would be accessing getMaximumScreenBrightnessSetting() method in PowerManager class using reflection. But I haven't tested it and therefore cannot confirm the results.

NB : If you are using this value to set brightness percentage, keep this in mind : From android 9 onwards, brightness is set logarithmically. So setting brightness percentage might not look like the percentage shown in brightness slider (Lower percentages might look higher than set value on brightness slider), but the physical brightness will be set right.


It is specific for some Xiaomi devices. For example Xiaomi Redmi Note 7 has 0-4000 range.

Official documentation defines SCREEN_BRIGHTNESS range as 0-255. So, I think there are no API to get the maximum value in brightness.

On some (not all) devices there is a file "/sys/class/leds/lcd-backlight/max_brightness" that can contain max value.


Instead of you set 255 as the max value. I prefer to use this way to set brightness to max. Just passing 1F to the screenBrightness.

WindowManager.LayoutParams layout = getWindow().getAttributes();
layout.screenBrightness = 1F;
getWindow().setAttributes(layout);

It's working fine on different android devices.