c19354837 / react-native-system-setting

A library to access system setting, and change it easily. eg: volume, brightness, wifi
MIT License
442 stars 159 forks source link

maxBrightness hardcode to 255 #118

Open jebai0521 opened 4 years ago

jebai0521 commented 4 years ago

now, we hardcode max brightness value to 255

https://github.com/c19354837/react-native-system-setting/blob/001d7efc72a1ae2b5bcb6c3d41846337c33508a5/android/src/main/java/com/ninty/system/setting/SystemSetting.java#L225

https://github.com/c19354837/react-native-system-setting/blob/001d7efc72a1ae2b5bcb6c3d41846337c33508a5/android/src/main/java/com/ninty/system/setting/SystemSetting.java#L255

https://github.com/c19354837/react-native-system-setting/blob/001d7efc72a1ae2b5bcb6c3d41846337c33508a5/android/src/main/java/com/ninty/system/setting/SystemSetting.java#L275

but, the value may not equal to 255 on some device

for example, the value is 4096 on Xiaomi, we could get value via the below code

    private static int getMaxBrightness() {
        int brightness = 255;
        try {
            Resources system = Resources.getSystem();
            int resId = system.getIdentifier("config_screenBrightnessSettingMaximum", "integer", "android");
            if (resId != 0) {
                brightness = system.getInteger(resId);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return brightness;
    }
xskipy commented 3 years ago

This seems like a good solution!
I'm having this issue too while testing on my Xiaomi device

dsumac commented 3 years ago

Do you have some news for this issue ?