Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Did Android fontscale quit working on new phones or is it just me?

My app works fine on my old phone (Android 9) but the scale function doesn’t work on my new Pixel 6a (android 12). The app was written long ago. The scale function allows the app to look correct with any user settings of font and screen size. I got the code on Stackoverflow long ago and noted in the comment. It has worked for years over many versions of Andriod starting with Andriod 4. Is there some permission on the phone I have to set or do I need to change the code so something else? Perhaps this is a bug. I did not see anything about this being depreciated code.

This code is on the sign-in screen and only runs once.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    ll = new mylocationlistener();
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
    setContentView(R.layout.notes);
    
       // code from stackoverflow to force locale.us 
    Locale.setDefault(Locale.US);
    Configuration config = new Configuration();
    float scale = getResources().getConfiguration().fontScale;
    config.locale = Locale.US;
    config.fontScale = scale;
    getBaseContext().getResources().updateConfiguration(config,getBaseContext().getResources().getDisplayMetrics());
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

UpdateConfiguration has been deprecated for a long time- since Android 25. The replacement is context.createConfigurationContext https://developer.android.com/reference/android/content/Context#createConfigurationContext(android.content.res.Configuration) which wraps your context with a new configuration, then allowing you to use that context instead of the activity where you need one.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading