Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Google Now or phone default voice search?

I need to give users a method to launch their phone's voice assistant from my app, be it Google Now or anything else.

When searching on how to do this I keep finding explanations on how to get voice input while I just want to launch Google Now in "listening" mode. This question clearly asks for the same thing but the accepted answer explains how to open voice input:

How to programmatically initiate a Google Now voice search?

I know this can't be a rare case, how can it be done?

like image 514
lisovaccaro Avatar asked Mar 23 '14 01:03

lisovaccaro


2 Answers

startActivity(new Intent(Intent.ACTION_VOICE_COMMAND).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

worked for me and seems more intuitive.

like image 103
Justin Harris Avatar answered Sep 28 '22 15:09

Justin Harris


It is not very clear what exactly you are trying to achieve, but I hope following will be helpful.

The code given at How to programmatically initiate a Google Now voice search? will launch the default speech recognizer (or "voice assistant" as you have put it).

Following, however, will explicitly open (if available) Google's speech recognizer:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.google.android.googlequicksearchbox",
        "com.google.android.googlequicksearchbox.VoiceSearchActivity");
try {
    startActivity(intent);
} catch (ActivityNotFoundException anfe) {
    Log.d(TAG, "Google Voice Search is not found");
}  
like image 25
ozbek Avatar answered Sep 28 '22 16:09

ozbek