how to show up the google voice recognition settings in my app?

前端 未结 2 1385
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 21:31

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 T

2条回答
  •  醉酒成梦
    2021-02-04 21:51

    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

提交回复
热议问题