Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Eimji committed Mar 25, 2019
1 parent 94eed98 commit 4b15436
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,18 @@ 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);
break;
case "speech.listen":
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, getLocale(call.arguments.toString()));
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, getAndroidLocaleCode(call.arguments.toString()));
speech.startListening(recognizerIntent);
result.success(true);
break;
Expand All @@ -87,9 +92,8 @@ public void onMethodCall(MethodCall call, Result result) {
}
}

private Locale getLocale(String code) {
String[] localeParts = code.split("_");
return new Locale(localeParts[0], localeParts[1]);
private String getAndroidLocaleCode(String code) {
return code.replace("_", "-");
}

@Override
Expand Down

0 comments on commit 4b15436

Please sign in to comment.