Created
December 13, 2012 06:32
-
-
Save xalexchen/4274535 to your computer and use it in GitHub Desktop.
when we want to change android system default language on our own application,we can use java reflection mechanism to invoke android non public methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
updateLanguage(Locale.SIMPLIFIED_CHINESE); | |
updateLanguage(Locale.ENGLISH); | |
.. | |
.. | |
.. | |
.. | |
private void updateLanguage(Locale locale) { | |
Log.d("ANDROID_LAB", locale.toString()); | |
try { | |
Object objIActMag, objActMagNative; | |
Class clzIActMag = Class.forName("android.app.IActivityManager"); | |
Class clzActMagNative = Class.forName("android.app.ActivityManagerNative"); | |
Method getDefault = clzActMagNative.getDeclaredMethod("getDefault"); | |
// IActivityManager iActMag = ActivityManagerNative.getDefault(); | |
objIActMag = getDefault.invoke(clzActMagNative); | |
// Configuration config = iActMag.getConfiguration(); | |
Method getConfiguration = clzIActMag.getDeclaredMethod("getConfiguration"); | |
Configuration config = (Configuration) getConfiguration.invoke(objIActMag); | |
config.locale = locale; | |
Class[] clzParams = { Configuration.class }; | |
Method updateConfiguration = clzIActMag.getDeclaredMethod( | |
"updateConfiguration", clzParams); | |
updateConfiguration.invoke(objIActMag, config); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment