Android Nougat 7.1 resets Locale after launching WebView -


we got weird behavior android n 7.1 ( api-25 ) after launching webview, system enforces reseting locale device locale. overrides used locale (for localization) on application. easy way reproduce localization on app. , launch webview. won't see localized content more until relaunching app again. happens on android-7.1 (api-25)

here how switch locale working in apis:

 public void switchtoczlocale() {         locale mlocale = new locale("cs","cz");// can other locale         configuration config = getbasecontext().getresources()                 .getconfiguration();         locale.setdefault(mlocale);         config.setlocale(mlocale);         getbasecontext().getresources().updateconfiguration(config, getbasecontext().getresources().getdisplaymetrics());     } 

i have uploaded sample reproduce issue more details on:

https://github.com/mabuthraa/webview-android7-issue

please idea if behavior bug or bad implantation of changing locale.

here link issue ticket on android group: issue 218310: [developer preview] creating webview resets locale user defaults

here workaround solution.

we resolved issue enforcing setting locale again after initializing webview , before loading content:

if (build.version.sdk_int >= build.version_codes.n) {   myapp.getapplication().switchtoczlocale(); } 

for example in webactivity:

 @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_web);         mwebview = (webview) findviewbyid(r.id.webview);         if (build.version.sdk_int >= build.version_codes.n) {           myapp.getapplication().switchtoczlocale();         }         mwebview.loaddata(getstring(r.string.web_content), "text/html", "charset=utf-8");     } 

myapp:

import android.app.application; import android.content.res.configuration;  import java.util.locale;   public class myapp extends application {     private static myapp sapplication;      @override     public void oncreate() {         super.oncreate();         switchtoczlocale();         sapplication = this;     }      public static myapp getapplication() {         return sapplication;     }      public void switchtoczlocale() {         locale mlocale = new locale("cs","cz");         configuration config = getbasecontext().getresources()                 .getconfiguration();         locale.setdefault(mlocale);         config.setlocale(mlocale);         getbasecontext().getresources().updateconfiguration(config, getbasecontext().getresources().getdisplaymetrics());     } } 

i hope may help,'.

still im looking better solution.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -