Execute Google Assistant programmatically

Viewed 442

Instead of saying "OK Google", I would like to open Google Assistant by clicking on a button in my own app.

So when in my app that button has been clicked, the user doesn't need to say "Ok Google". They will just simply press the button, then Google Assistant will start and then they can say whatever they want to say. Is that possible?

1 Answers

The activity action android.intent.action.VOICE_ASSIST can be used to search on the internet for specific keywords. For example, it can be said "What's the current date?", then this page will be opened, and the current date will also be spoken. Or you can ask anything. As long as Wikipedia is first listed on Google, a brief summary of Wikipedia's content will be spoken. If there is no answer from Wikipedia or from Google itself, the entry will be searched on the search engine of Google, but there is silence.

This is how it should be used:

Intent googleAssistant = new Intent("android.intent.action.VOICE_ASSIST");
startActivity(googleAssistant);

You can also use other actions. For instance com.google.android.gms.actions.SEARCH_ACTION, if you want to search for a place or android.intent.action.SET_ALARM to set an alarm.

However, this will not be the best answer since it will not work exactly the same as Google Assistant. So the entertainment part (e.g. "Tell me a joke") cannot be used.

References

Related