Adding screen brightness controls to android application

后端 未结 3 1919
清歌不尽
清歌不尽 2020-11-30 01:30

I am looking to add controls to adjust screen brightness locally in my app menu but can\'t seem to figure out how to do it. I have seen examples to max-out or dim brightness

3条回答
  •  误落风尘
    2020-11-30 01:51

    You can change the user's brightness setting like this (make sure you declare permission for WRITE_SETTINGS in the manifest)

    android.provider.Settings.System.putInt(getContentResolver(), 
                            android.provider.Settings.System.SCREEN_BRIGHTNESS, brightpref);
    

    The documentation calls that setting from 0 to 255. I am trying to figure out whether it shuts the screen off at 0, as at one point I had a widget installed with a slider and you'd cause the screen to shut off if you set it to 0.

提交回复
热议问题