android - 如何以编程方式启动 Google Now 语音搜索?

标签 android android-search google-now

我想在用户按下按钮时启动 Google Now 语音搜索。但是,我在文档中找不到开始搜索的 Intent 。

有人知道如何开始Google Now 语音搜索的 Activity 吗?

最佳答案

语音输入的调用 Activity :

/* 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();
}

从字符串中获取输入:

(我已用于在搜索 View 中设置文本并搜索该值)

/* 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 - 如何以编程方式启动 Google Now 语音搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18049157/

相关文章:

php - JSONException : Value of type java. lang.String 无法转换为 JSONObject

android - 如何使Android应用程序只能安装在单个设备上?

安卓搜索 View : What is the difference between setOnFocusChangeListener() and setOnQueryTextFocusChangeListener?

android - 新的 Google Now 和 Google+ 卡片界面

android - 停止识别 Google Now 滑动手势

android - 如何通过添加搜索查询的 Intent 启动 GoogleNow?

Java:从 URI 构造文件?

android - 如何更改xml布局中的矩形颜色

android - 禁用长按 SearchView EditText

android - 如何在 SearchView 中禁用 ActionMode