android - Read font size from Settings -
this question dublicate of android app: how read font size under settings? read answer of commonsware points use settings.system.font_scale. wrote few lines:
float scale = -66.6f; try { scale = android.provider.settings.system.getfloat(getcontentresolver(), android.provider.settings.system.font_scale); } catch(settingnotfoundexception e) { log.e(getclass().getsimplename(), "error: ", e); } toast.maketext(this, "scale=" + scale, toast.length_long).show(); my problem settingnotfoundexception i'm using android 4.2.2 device. way code in oncreate callback of activity.
i googled problem , found 3 sites uses same code. special permission required? tried permission android.permission.write_settings without success.
i found in source code of settings.system function:
/** @hide */ public static void getconfigurationforuser(contentresolver cr, configuration outconfig, int userhandle) { outconfig.fontscale = settings.system.getfloatforuser( cr, font_scale, outconfig.fontscale, userhandle); if (outconfig.fontscale < 0) { outconfig.fontscale = 1; } } there font_scale in usage checked configuration class documentation points getresources().getconfiguration(). cound fix code using:
float scale = getresources().getconfiguration().fontscale;
Comments
Post a Comment