Android Question Changing Locale of Android

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Anyone know how change the Android Locale?

Is possible with CORE of B4A or need create a library with this routine?

Class localClass = Class.forName("android.app.ActivityManagerNative");
Object localObject = localClass.getMethod("getDefault", null).invoke(localClass, null);
Configuration localConfiguration = (Configuration)localObject.getClass().getMethod("getConfiguration", null).invoke(localObject, null);
localConfiguration.locale = paramLocale;
setUserSetLocale(localConfiguration, true);
localObject.getClass().getMethod("updateConfiguration", new Class[] { Configuration.class }).invoke(localObject, new Object[] { localConfiguration });
 

lorebarita

Member
Licensed User
Longtime User
Sub img_french_Click
Dim objVisualNet As VisualNet
objVisualNet.Initialize("VisualNet")
objVisualNet.ChangeLocale("fr","FR")
End Sub
Sub img_english_Click
Dim objVisualNet As VisualNet
objVisualNet.Initialize("VisualNet")
objVisualNet.ChangeLocale("en","US")
End Sub

This is what I am trying to achieve but I get the error above on a Chinese phone(Rugged phone) My phone is not rooted. But it works with a SAMSUNG phone. What do I need to do
 
Upvote 0

agb2008

Member
Licensed User
Longtime User
Hello Martin,

Could you please advice how I could define new Locale to be used with Resources lib ?
I need to add support for language (locale) not listed in your Resources lib.
But I can't find a way how I could add additional one to the list of already supported.
Thank you beforehand,

Alexey

P.S.

Looks like I found a workaroud:

B4X:
    Dim ApplicationResources As Resources
    Dim DeviceLocale As Locale

    DeviceLocale.Initialize("ru")

    ApplicationResources.SetDefaultLocale(DeviceLocale)
    ApplicationResources.Initialize(ApplicationResources.RESOURCE_SOURCE_APPLICATION)
 
Last edited:
Upvote 0
Top