Search code examples
androidfont-sizescreen-brightness

how to set the screen brightness and Font-Scale in android


iam setting the device settings into certain values. i want to adjust the screen brightness and the Font-Scale iam using the following code:

//For Font-Scale
Settings.System.putFloat(this.getContentResolver(),Settings.System.FONT_SCALE,(float) 1.3);
//For Brightness
Settings.System.putString(this.getContentResolver(),Settings.System.SCREEN_BRIGHTNESS,255);

the value of the brightness does change but to set activate it i must go to the screen settings and open the brightness settings and press OK. the value of the Font-Scale Does not change. i think maybe a way to refresh the settings to get the new values. can any one help me?


Solution

  • This cannot be done by apps. One way to get these settings to take effect is by rebooting the phone. If you have root access you can use non-public apis. use below code to do it using reflection.

    To change brightness you need to call

     PowerManagerService.setBacklightBrightness(brightness);
    

    And to change

     ActivityManagerNative.getDefault().updatePersistentConfiguration(mCurConfig)