How to send a text query to Google Assistant from Android app

与世无争的帅哥 提交于 2021-01-27 21:19:28

问题


I'm trying to start Google Assistant and send a text question (not voice) from my app when I press a button. For example: I click a button, and the Google Assistant answer to my question "How is the weather today?".

Is this possible?

EDIT: When I press a button I want the Google Assistant to do some actions and give a spoken feedback. For example: "Read the weather for tomorrow and set the alarm to 6.30 am".


回答1:


It looks as though you can reference it from a direct package class name.

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);



回答2:


If you're already using the Assistant SDK, it's pretty simple. Just replace AudioInConfig with a text query. Here's how I do it:

AssistConfig config = AssistConfig.newBuilder()
    .setTextQuery("Your text query goes here!")
    //.setAudioInConfig(audioInConfig)
    .setAudioOutConfig(audioOutConfig)
    .setDeviceConfig(deviceConfig)
    .setDialogStateIn(dialogStateIn)
    .setScreenOutConfig(screenOutConfig)
    .build();
AssistRequest request = AssistRequest.newBuilder().setConfig(config).build();

Then send the request to the server over gRPC and you'll get a spoken response back.



来源:https://stackoverflow.com/questions/52822530/how-to-send-a-text-query-to-google-assistant-from-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!