在我的Android应用程序中,我创建了一个带有磨损功能的通知,并添加了识别语音输入的动作并将语音文本发送到另一个活动。我的问题是它只是识别谷歌现在设置中选择的语言(英语),我想从波斯语中获得声音。这是我的代码:
RemoteInput remoteInput = new RemoteInput.Builder("My_Const_String")
.setLabel("label when you talk")
.build();
Intent replayIntent = new Intent(context, MyTestActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, replayIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action action = new NotificationCompat.Action.Builder(
R.drawable.ic_btn, "Label when confirm your talk", pendingIntent)
.addRemoteInput(remoteInput)
.build();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle("Title")
.setContentText("Content text")
.setSmallIcon(R.drawable.ic_stat_name)
.setContentText("My text02");
NotificationCompat.WearableExtender extender =
new NotificationCompat.WearableExtender();
extender.addAction(action);
builder.extend(extender);
NotificationManagerCompat mgr = NotificationManagerCompat.from(context);
int NotificatinId = 1;
mgr.notify(NotificatinId, builder.build());
此外,我不想强制用户手动更改谷歌的设置。我尝试添加额外的如下,但它没有奏效:
Intent i = new Intent();
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "fa_IR");
i.putExtra(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES, "fa_IR");
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "fa");
Bundle bundle = new Bundle();
bundle = i.getExtras();
RemoteInput remoteInput = new RemoteInput.Builder("My_Const_String")
.setLabel("label when you talk")
.addExtras(bundle)
.build();