From 29914578c93f3f13c756a52a5204c9751a6ff4e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0tol?= Date: Sun, 17 Mar 2019 11:16:39 +0100 Subject: [PATCH 1/3] Fix: getConfiguration().locale field was deprecated in API level 24 --- .../speechrecognition/SpeechRecognitionPlugin.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/bz/rxla/flutter/speechrecognition/SpeechRecognitionPlugin.java b/android/src/main/java/bz/rxla/flutter/speechrecognition/SpeechRecognitionPlugin.java index c925297..ae4cb42 100644 --- a/android/src/main/java/bz/rxla/flutter/speechrecognition/SpeechRecognitionPlugin.java +++ b/android/src/main/java/bz/rxla/flutter/speechrecognition/SpeechRecognitionPlugin.java @@ -7,6 +7,7 @@ import android.speech.RecognizerIntent; import android.speech.SpeechRecognizer; import android.util.Log; + import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; @@ -58,7 +59,12 @@ public void onMethodCall(MethodCall call, Result result) { case "speech.activate": // FIXME => Dummy activation verification : we assume that speech recognition permission // is declared in the manifest and accepted during installation ( AndroidSDK 21- ) - Locale locale = activity.getResources().getConfiguration().locale; + Locale locale; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { + locale = activity.getResources().getConfiguration().getLocales().get(0); + } else { + locale = activity.getResources().getConfiguration().locale; + } Log.d(LOG_TAG, "Current Locale : " + locale.toString()); speechChannel.invokeMethod("speech.onCurrentLocale", locale.toString()); result.success(true); From b175aa509d200dc649fc28729ff5e32fa4265567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0tol?= Date: Tue, 26 Mar 2019 10:51:00 +0100 Subject: [PATCH 2/3] Example fix --- example/lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index a5094aa..66cb297 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -50,7 +50,7 @@ class _MyAppState extends State { _speech.setCurrentLocaleHandler(onCurrentLocale); _speech.setRecognitionStartedHandler(onRecognitionStarted); _speech.setRecognitionResultHandler(onRecognitionResult); - _speech.setRecognitionCompleteHandler(onRecognitionComplete); + _speech.setRecognitionCompleteHandler((_) => onRecognitionComplete()); _speech.setErrorHandler(errorHandler); _speech .activate() From 63d3cb2300d8e6e0a90d69b3319b2bf09d82b277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0tol?= Date: Mon, 6 May 2019 16:09:50 +0200 Subject: [PATCH 3/3] better code reuse --- .../flutter/speechrecognition/SpeechRecognitionPlugin.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/bz/rxla/flutter/speechrecognition/SpeechRecognitionPlugin.java b/android/src/main/java/bz/rxla/flutter/speechrecognition/SpeechRecognitionPlugin.java index ae4cb42..90e7c58 100644 --- a/android/src/main/java/bz/rxla/flutter/speechrecognition/SpeechRecognitionPlugin.java +++ b/android/src/main/java/bz/rxla/flutter/speechrecognition/SpeechRecognitionPlugin.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.content.Intent; +import android.content.res.Configuration; import android.os.Bundle; import android.speech.RecognitionListener; import android.speech.RecognizerIntent; @@ -59,11 +60,12 @@ public void onMethodCall(MethodCall call, Result result) { case "speech.activate": // FIXME => Dummy activation verification : we assume that speech recognition permission // is declared in the manifest and accepted during installation ( AndroidSDK 21- ) + Configuration config = activity.getResources().getConfiguration(); Locale locale; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { - locale = activity.getResources().getConfiguration().getLocales().get(0); + locale = config.getLocales().get(0); } else { - locale = activity.getResources().getConfiguration().locale; + locale = config.locale; } Log.d(LOG_TAG, "Current Locale : " + locale.toString()); speechChannel.invokeMethod("speech.onCurrentLocale", locale.toString());