Seguro que es algo muy sencillo pero llevo varias horas intentando averiguar cómo obtener el lenguaje usado en un dispositivo. Sabiendo esto presentaré mi aplicación en un idioma u otro.
Os agradecería mucho si podéis darme alguna pista.
17.19 Getting language and country from device You can get the current language and country from a device with the following code.
Sub Activity_Create(FirstTime As Boolean)
Log(GetDefaultLanguage)
End Sub
Sub GetDefaultLanguage
Dim r As Reflector
r.Target = r.RunStaticMethod("java.util.Locale", "getDefault", Null, Null)
Return
r.RunMethod("getDisplayName")
End Sub
GetDefaultLanguage returns a string with the language and the country. Needs the Reflection library (available only for users who bought Basic4Android) ! Examples: English (United States) Deutsch (Österreich) français (Suisse)
Copié el código tal cual y funciona, lo único es que devuelve una descripción larga del idioma, pero sirve igualmente. Tengo que investigar un poco más.
Sub GetDefaultLanguage
Dim r As Reflector
r.Target = r.RunStaticMethod("java.util.Locale", "getDefault", Null, Null)
Return r.RunMethod("getDisplayName")
Una forma fácil y precisa es como dicen usando la libreria Reflection.
B4X:
Dim r As Reflector
Dim language As String
r.Target = r.RunStaticMethod("java.util.Locale", "getDefault", Null, Null)
language = r.RunMethod("getLanguage")
Esto te devuelve las dos primeras iniciales del idioma ("en" - english, "es" spanish, "fr" - frances, etc)