如何以编程方式启动Google即时语音search?

我想在用户按下button时开始Google即时语音search 。 但是,我无法find在文档中开始search的意图。

有人知道如何开始Google Now语音search的活动吗?

Solutions Collecting From Web of "如何以编程方式启动Google即时语音search?"

使用ACTION_RECOGNIZE_SPEECH

 private static final int RECOGNIZER_REQ_CODE = 1234; Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); startActivityForResult(intent, RECOGNIZER_REQ_CODE); 

请注意,您必须使用startActivityForResult()因为startActivity()不受支持。 有关详细信息,请参阅上面的链接文档。

呼叫活动的语音input:

 /* Call Activity for Voice Input */ Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US"); try { startActivityForResult(intent, 1); } catch (ActivityNotFoundException a) { Toast.makeText(context, "Oops! Your device doesn't support Speech to Text",Toast.LENGTH_SHORT).show(); } 

从string获取input:

(我用于在search视图中设置文本并search该值)

 /* When Mic activity close */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case 1: { if (resultCode == Activity.RESULT_OK && null != data) { String yourResult = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS).get(0); } break; } } } 

您需要启动一个活动,只有设置为android.intent.action.VOICE_ASSIST的操作,并popupGoogle Now语音识别器。 尝试使用开发人员工具:

 adb shell am start -a android.intent.action.VOICE_ASSIST