Question

Je travaille sur une application Android dans laquelle j'ai implémenté la reconnaissance vocale et le TTS.Je pensais donc lancer l'écran des paramètres pour la reconnaissance vocale Google et TTS afin de permettre à l'utilisateur de modifier les paramètres depuis l'application. J'ai implémenté avec succès les paramètres TTS en utilisant le code suivant:

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

Maintenant, je veux afficher les "paramètres de reconnaissance vocale google" du système dans mon application pour permettre à l'utilisateur de changer les options de langue, etc. J'ai beaucoup recherché ... J'ai fait beaucoup d'appels et j'ai essayé, mais je n'ai pas réussi à charger l'écran des paramètres de reconnaissance vocale.Veuillez me dire comment je peux mettre cela en œuvre. Merci d'avance ...

Était-ce utile?

La solution

J'étais coincé là-dessus pendant des lustres aussi ...

    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);
    }

J'espère que cela le fera aussi pour vous ...

EDIT: Comme indiqué dans les commentaires, cela a changé dans la version Jelly Bean de l'application de recherche Google.Pour détecter d'éventuels problèmes de mise à jour où vous ne pouvez pas utiliser Build.Version, vous pouvez utiliser quelque chose du genre:

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();
}
}

Autres conseils

La réponse @brandall ne fonctionne pas pour moi sous Android 5.1, par exemple un autre nom de composant est utilisé pour les paramètres de reconnaissance vocale.

/**
 * 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: mis à jour avec le dernier nom du composant

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top