Question

I am working on an android application in which i have implemented voice recognition and TTS. So i was thinking to launch settings screen for both google voice recognition and TTS to allow user to change settings from within the application. I have implemented TTS settings successfully by using following code:

intent = new Intent();
intent.setAction("com.android.settings.TTS_SETTINGS");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);

Now I want to show system's "google voice recognition settings" in my application to allow user to change language options etc. I have searched a lot... Done a lot of hit and try but failed to load voice recognition settings screen. Please tell me how i can implement that. Thanks in advance...

Was it helpful?

Solution

I was stuck on this for ages too...

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setComponent(newComponentName("com.google.android.voicesearch","com.google.android.voicesearch.VoiceSearchPreferences"));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    this.startActivity(intent);
    }

Hope it does for you too...

EDIT: As pointed out in the comments, this changed in the Jelly Bean version of the Google Search App. To catch any potential update issues where you can't use Build.Version, you can use something along these lines:

try {
final Intent vsInt = new Intent(Intent.ACTION_MAIN);
vsInt.setComponent(new ComponentName("com.google.android.voicesearch",
                            "com.google.android.voicesearch.VoiceSearchPreferences"));
vsInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(vsInt);

} catch (final Exception e) {

try {
final Intent vsjInt = new Intent(Intent.ACTION_MAIN);
vsjInt.setComponent(new ComponentName("com.google.android.googlequicksearchbox", "com.google.android.voicesearch.VoiceSearchPreferences"));
vsjInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(vsjInt);

} catch (final Exception e1) {
e1.printStackTrace();
}
}

OTHER TIPS

The @brandall answer doesn't work at Android 5.1 for me such as another component name is used for the voice recognition settings there.

/**
 * Open speech recognition settings activity
 *
 * @return true in case activity was launched, false otherwise
 **/
public boolean openSpeechRecognitionSettings() {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    boolean started = false;
    ComponentName[] components = new ComponentName[]{
            new ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.settingsui.VoiceSearchPreferences"),
            new ComponentName("com.google.android.voicesearch", "com.google.android.voicesearch.VoiceSearchPreferences"),
            new ComponentName("com.google.android.googlequicksearchbox", "com.google.android.voicesearch.VoiceSearchPreferences"),
            new ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.velvet.ui.settings.VoiceSearchPreferences")
    };
    for (ComponentName componentName : components) {
        try {
            intent.setComponent(componentName);
            startActivity(intent);
            started = true;
            break;
        } catch (final Exception e) {
            Timber.e(e, null);
        }
    }
    return started;
}

EDIT: updated with the latest component name

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top