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

前端 未结 2 1475
被撕碎了的回忆
被撕碎了的回忆 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:57

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

提交回复
热议问题