From 6834ac884e272926b0c5e9f3be5c1ba6c2ac8faa Mon Sep 17 00:00:00 2001 From: Ivan Date: Mon, 25 Feb 2019 10:29:16 +0400 Subject: [PATCH] fix sendLocales on old android versions (flutter/engine#7937) [Configuration.getLocales()][1] was added in API level 24. For earlier versions, we instead return only the current locale. Fixes https://github.com/flutter/flutter/issues/28321 [1]: https://developer.android.com/reference/android/content/res/Configuration#getLocales() --- .../android/io/flutter/view/FlutterView.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java index e636506d22..8c40ed6325 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java @@ -320,12 +320,16 @@ public class FlutterView extends SurfaceView } private void sendLocalesToDart(Configuration config) { - LocaleList localeList = config.getLocales(); - int localeCount = localeList.size(); List locales = new ArrayList<>(); - for (int index = 0; index < localeCount; ++index) { - Locale locale = localeList.get(index); - locales.add(locale); + if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { + LocaleList localeList = config.getLocales(); + int localeCount = localeList.size(); + for (int index = 0; index < localeCount; ++index) { + Locale locale = localeList.get(index); + locales.add(locale); + } + } else { + locales.add(config.locale); } localizationChannel.sendLocales(locales); }