Hello,
I need to get phone language.
Searching in internet, I found this Java code:
Well, the line
no problem, here is the code:
and it works very well with API 26 and later, but the line (for API < 26)
I don't know how to do it
I tried
The ERROR is: java.lang.RuntimeException: Method: locale not found in: android.content.res.Configuration
I try with
but don't works, I think that the problem is RunMethod
Thanks
Sergio
I need to get phone language.
Searching in internet, I found this Java code:
B4X:
Locale locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
locale = Resources.getSystem().getConfiguration().getLocales().get(0);
} else {
//noinspection deprecation
locale = Resources.getSystem().getConfiguration().locale;
}
Well, the line
B4X:
locale = Resources.getSystem().getConfiguration().getLocales().get(0);
B4X:
Dim Resources As JavaObject
Resources = Resources.InitializeStatic("android.content.res.Resources").RunMethodJO("getSystem", Null).RunMethodJO("getConfiguration", Null).RunMethodJO("getLocales", Null)
Dim locale As String = Resources.RunMethod("get", Array(0))
B4X:
locale = Resources.getSystem().getConfiguration().locale;
I tried
B4X:
Dim Resources As JavaObject
Resources = Resources.InitializeStatic("android.content.res.Resources").RunMethodJO("getSystem", Null).RunMethod("getConfiguration", Null)
' until here it works, now I don't know how get "locale"
Dim str As String = Resources
Log(str) ' this works, it show to me "Resources" variable, I see inside it "en_GB", but I don't how to extract it correctly
Dim locale As String = Resources.RunMethod("locale", Null) ' <<<<<<< ERROR
Log(locale)
I try with
B4X:
Dim locale As List
Thanks
Sergio