Private voidupdatelanguage (locale locale) {Try{Object objiactmag, objactmagnative; Class Clziactmag= Class.forName ("Android.app.IActivityManager"); Class clzactmagnative= Class.forName ("android.app.ActivityManagerNative"); Method Mtdactmagnative$getdefault= Clzactmagnative.getdeclaredmethod ("Getdefault"); //Iactivitymanager Iactmag = Activitymanagernative.getdefault ();Objiactmag =Mtdactmagnative$getdefault.invoke (clzactmagnative); //Configuration config = iactmag.getconfiguration ();Method mtdiactmag$getconfiguration = Clziactmag.getdeclaredmethod ("GetConfiguration"); Configuration Config=(Configuration) Mtdiactmag$getconfiguration.invoke (OBJIACTMAG); Config.locale=locale; //iactmag.updateconfiguration (config); //you need to declare permissions here: Android.permission.CHANGE_CONFIGURATION//onCreate () will be called again;Class[] Clzparams = {Configuration.class }; Method mtdiactmag$updateconfiguration=Clziactmag.getdeclaredmethod ("updateconfiguration", Clzparams); Mtdiactmag$updateconfiguration.invoke (objiactmag, config); } Catch(Exception e) {e.printstacktrace (); } }
Parameters are obtained from Local, for example: Local.english;
Before use should root system, adb shell
->su
Then # PM Grant Com.example.clickdemo Android.permission.CHANGE_CONFIGURATION manually give permission, otherwise the reflection exception will be reported
Android modifies Android system Language using the Java reflection mechanism