首页 > 解决方案 > 如何从 Android 应用向 Google 助理发送文本查询

问题描述

当我按下按钮时,我正在尝试启动 Google Assistant 并从我的应用程序发送一个文本问题(不是语音)。例如:我点击一个按钮,Google 助理会回答我的问题“今天天气怎么样?”。

这可能吗?

编辑: 当我按下按钮时,我希望 Google 助理执行一些操作并提供语音反馈。例如:“阅读明天的天气并将闹钟设置为早上 6.30”。

标签: androidgoogle-assistant-sdk

解决方案


看起来您可以从直接的包类名称中引用它。

String queryString = "How is the weather today?";
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.setClassName("com.google.android.googlequicksearchbox", 
                    "com.google.android.googlequicksearchbox.SearchActivity");
intent.putExtra("query", queryString);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

推荐阅读