Home:ALL Converter>how to send command to Google Assistant from Android

how to send command to Google Assistant from Android

Ask Time:2020-01-15T15:03:52         Author:qwerty

Json Formatter

I want to start Google Assistant with a specific command interaction from my app.

I tried:

Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.setClassName("com.google.android.googlequicksearchbox", "com.google.android.googlequicksearchbox.SearchActivity");
intent.putExtra(SearchManager.QUERY, "my command");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

It shows a web search result on google web. It is not the result what I want.

And I also tried:

Intent intent = new Intent(Intent.ACTION_VOICE_COMMAND);
intent.putExtra(SearchManager.QUERY, "my command");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

From the above code, Google Assistant is started and ready for user voice command. "my command" dose not work.

.

Expected result with the above code:

If 'my command' is "what time is it now?", the current time should be shown on the screen.

The action should be same as when user call Google Assistant with "what time is it now?".

Referred: Sending commands to Google Assistant from Android app

Any ideas?

Author:qwerty,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/59746497/how-to-send-command-to-google-assistant-from-android
yy