3

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

Stefan
  • 352
  • 2
  • 17

2 Answers2

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);
Jay Snayder
  • 4,298
  • 4
  • 27
  • 53
  • 2
    I want the Google Assistant to do some actions and give a spoken feedback, not only to open the Google app and search for the weather. – Stefan Oct 16 '18 at 16:36
0

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.

Greg Moens
  • 1,705
  • 8
  • 15
  • I have never used the Assistant SDK before and I am trying to use it in my Android project in the moment so I can't use this code right now. – Stefan Nov 10 '18 at 19:15