Launch Google Now or phone default voice search?
Asked Answered
D

2

5

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?

Druse answered 23/3, 2014 at 1:22 Comment(1)
The answer in linked question works perfectly fine. As far as I understand you want to do two things: 1) launch Google Now, and then 2) start speech recognizer.Jaine
J
4

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");
}  
Jaine answered 28/3, 2014 at 12:16 Comment(3)
I'm going to try it tonight. Is the voice assistant the same as the speech recognizer? I thought the speech recognizer only did speech to text translation whereas the voice assistant actually did stuff you asked to, e.g: "call my mom". So my question is basically, will this call my mom?Druse
I did not test, but yes it should (given that Google's speech recognizer is available).Jaine
The problem is, your application is minimized and after the user completes the search session, he will no longer be inside the app. The answer by @Justin doesn't minimize the app and thus is better.Gladden
A
5
startActivity(new Intent(Intent.ACTION_VOICE_COMMAND).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

worked for me and seems more intuitive.

Adkisson answered 14/7, 2014 at 0:54 Comment(2)
If i installed Svoice and Google voice and set Svoice as default app. The above code always call my Google voice. Why?Bracken
You probably have S Voice set as your default. You can change this in your settings somehow (sorry I don't know how).Adkisson
J
4

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");
}  
Jaine answered 28/3, 2014 at 12:16 Comment(3)
I'm going to try it tonight. Is the voice assistant the same as the speech recognizer? I thought the speech recognizer only did speech to text translation whereas the voice assistant actually did stuff you asked to, e.g: "call my mom". So my question is basically, will this call my mom?Druse
I did not test, but yes it should (given that Google's speech recognizer is available).Jaine
The problem is, your application is minimized and after the user completes the search session, he will no longer be inside the app. The answer by @Justin doesn't minimize the app and thus is better.Gladden

© 2022 - 2024 — McMap. All rights reserved.