I'm developing an app that needs to detect the language currently set in the device.
I tried something like this:
Unfortunately, that code doesn't work when the app makes use of values-xx folders with their own strings.xml. In such case, GetLanguage returns the language of the app rather than the device's locale.
According to this discussion https://stackoverflow.com/questions/4212320/get-the-current-language-in-device It seems that a call to:
should fix the problem.
How could that be translated to B4A by using JavaObject/Reflection?
I tried something like this:
B4X:
Sub GetLanguage As String
Dim jo As JavaObject
Dim str As String
str = jo.InitializeStatic("java.util.Locale").RunMethod("getDefault", Null)
If str.Length>=2 Then
str = str.SubString2(0,2).ToLowerCase
Else
str = ""
End If
Return str
End Sub
Unfortunately, that code doesn't work when the app makes use of values-xx folders with their own strings.xml. In such case, GetLanguage returns the language of the app rather than the device's locale.
According to this discussion https://stackoverflow.com/questions/4212320/get-the-current-language-in-device It seems that a call to:
B4X:
ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration());
should fix the problem.
How could that be translated to B4A by using JavaObject/Reflection?