diff --git a/android/src/main/java/com/example/devicelocale/DevicelocalePlugin.java b/android/src/main/java/com/example/devicelocale/DevicelocalePlugin.java index 40d005f..bfa7643 100644 --- a/android/src/main/java/com/example/devicelocale/DevicelocalePlugin.java +++ b/android/src/main/java/com/example/devicelocale/DevicelocalePlugin.java @@ -11,6 +11,8 @@ import androidx.core.os.LocaleListCompat; import android.content.Context; import android.content.ContextWrapper; +import android.os.Build; + import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -49,7 +51,7 @@ public void onMethodCall(MethodCall call, @NonNull Result result) { } private String getCurrentLocale() { - return Locale.getDefault().toString(); + return getLocaleTag(Locale.getDefault()); } private List getPreferredLanguages() { @@ -58,7 +60,7 @@ private List getPreferredLanguages() { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { LocaleListCompat list = LocaleListCompat.getAdjustedDefault(); for (int i = 0; i < list.size(); i++) { - result.add(list.get(i).toString()); + result.add(getLocaleTag(list.get(i))); } } else { result.add(getCurrentLocale()); @@ -66,4 +68,12 @@ private List getPreferredLanguages() { return result; } + + private String getLocaleTag(Locale locale) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + return locale.toLanguageTag(); + } else { + return locale.toString(); + } + } }