Question

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?

Était-ce utile?

La 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)

Autres conseils

check the source code DisplaySettings.java, here is the method to control font size scale

public void writeFontSizePreference(Object objValue) {
    try {
        mCurConfig.fontScale = Float.parseFloat(objValue.toString());
        ActivityManagerNative.getDefault().updatePersistentConfiguration(mCurConfig);
    } catch (RemoteException e) {
        Log.w(TAG, "Unable to save font size");
    }
}

here is a solution keep the font size in different fontscale.

float textSize = 22f;
mTextView.setTextSize(textSize / getResources().getConfiguration().fontScale);

and I think @shoe rat's answer is more better for an activity or application context.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top