Home > Back-end >  Did Android fontscale quit working on new phones or is it just me?
Did Android fontscale quit working on new phones or is it just me?

Time:08-10

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());
}

CodePudding user response:

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.

  • Related