pat*_*215 19 android android-search google-now
我想在用户按下按钮时启动Google即时语音搜索.但是,我找不到意图在文档中开始搜索.
有人知道如何开始Google Now语音搜索的活动吗?
Pra*_*ani 11
/* 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();
}
Run Code Online (Sandbox Code Playgroud)
(我在搜索视图中用于设置文本并搜索该值)
/* 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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
private static final int RECOGNIZER_REQ_CODE = 1234;
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
startActivityForResult(intent, RECOGNIZER_REQ_CODE);
Run Code Online (Sandbox Code Playgroud)
请注意,您必须使用startActivityForResult()为startActivity()不支持.有关详细信息,请参阅上述链接文档.
小智 8
您需要启动一个仅设置了Action的活动,android.intent.action.VOICE_ASSIST并弹出Google Now语音识别器.使用开发人员工具尝试:
adb shell am start -a android.intent.action.VOICE_ASSIST
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15979 次 |
| 最近记录: |