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..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,11 +2,13 @@ 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; 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 +60,13 @@ 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; + Configuration config = activity.getResources().getConfiguration(); + Locale locale; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { + locale = config.getLocales().get(0); + } else { + locale = config.locale; + } Log.d(LOG_TAG, "Current Locale : " + locale.toString()); speechChannel.invokeMethod("speech.onCurrentLocale", locale.toString()); result.success(true); 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()