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