2
文字我已经创建了一个排序的永久notification
,我的目标是这样谷歌语音从通知
1)用户轻敲notification
2)Google Speech to Text activity
启动,并需要语音输入
3)输入被转换为文本,并开始一个新的活动,它显示文本。
这里就是我一直如此far--
NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this)
.setSmallIcon(android.R.drawable.ic_dialog_alert)
.setContentTitle("Tap for voice input")
.setContentText("Hi");
Intent resultIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
resultIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
resultIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
resultIntent.putExtra(RecognizerIntent.EXTRA_PROMPT,
getString(R.string.speech_prompt));
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
Notification notification = builder.build();
notification.flags = Notification.FLAG_NO_CLEAR;
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(MainActivity.this);
notificationManager.notify(0, notification);
现在我知道我可以正常使用startActivityForResult(resultIntent, REQ_CODE_SPEECH_INPUT);
,在我activity
处理它处理识别Intent
的结果。
但我必须通过pendingIntent
我的意图为notification
。
我可以做到这一点吗?
编辑1:
我就可以开始一个新的活动,然后打开语音谷歌语音提示,但我想转换后的字符串要传递给我的活动开始之前,就像在一个额外的参数意图...
我认为提供的答案最适合您的需求 - 否则,如果您想获得更多技术,可以使用SpeechRecognizer类从服务获取语音输入,然后将参数传递给活动一旦完成。 – brandall