简体   繁体   English

如何在我的应用程序中显示谷歌语音识别设置?

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

I am working on an android application in which i have implemented voice recognition and TTS. 我正在开发一个Android应用程序,我已经实现了语音识别和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. 所以我打算启动谷歌语音识别和TTS的设置屏幕,以允许用户从应用程序内更改设置。 I have implemented TTS settings successfully by using following code: 我使用以下代码成功实现了TTS设置:

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... 提前致谢...

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. 对于我来说,@ brandall答案在Android 5.1上不起作用,例如另一个组件名称用于语音识别设置。

/**
 * 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 编辑:使用最新的组件名称更新

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. 编辑:正如评论中指出的那样,谷歌搜索应用程序的Jelly Bean版本发生了变化。 To catch any potential update issues where you can't use Build.Version, you can use something along these lines: 要捕获任何无法使用Build.Version的潜在更新问题,您可以使用以下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM