简体   繁体   中英

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

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".

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM