【问题标题】:how to show up the google voice recognition settings in my app?如何在我的应用中显示谷歌语音识别设置?
【发布时间】:2012-02-10 17:01:39
【问题描述】:

我正在开发一个已实现语音识别和 TTS 的 android 应用程序。所以我正在考虑为谷歌语音识别和 TTS 启动设置屏幕,以允许用户从应用程序中更改设置。 我已经使用以下代码成功实现了 TTS 设置:

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

现在我想在我的应用程序中显示系统的“谷歌语音识别设置”,以允许用户更改语言选项等。我已经搜索了很多...做了很多点击并尝试但未能加载语音识别设置屏幕.请告诉我如何实施。 提前谢谢...

【问题讨论】:

    标签: android settings show voice-recognition


    【解决方案1】:

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

    编辑:使用最新的组件名称更新

    【讨论】:

    • 适用于 Android 4.4.2
    • @httpdispatch on Android 7.1.1 Settings -> Languages & Input -> Virtual keyboard -> Google Voice typing 显示设置。
    • @AdrianBuciuman 我已在答案中添加了新组件名称,但由于 SecurityException,第三方应用程序无法打开该窗口。我不确定是否有任何解决方法
    • @AdrianBuciman 看起来我找到了正确的组件名称。请检查更新的答案。非常感谢您的发现。
    • @AdrianBuciuman 我已经打开了您在“虚拟键盘”设置中找到的窗口并检查了 logcat 输出。在那里我找到了下一条记录 /ActivityManager: START u0 {act=android.intent.action.MAIN cmp=com.google.android.googlequicksearchbox/com.google.android.apps.gsa.settingsui.VoiceSearchPreferences} from uid 1000 on display 0
    【解决方案2】:

    我也被这个问题困扰了很久......

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

    希望它也适合你......

    编辑:正如 cmets 中所指出的,这在 Google 搜索应用程序的 Jelly Bean 版本中发生了变化。要发现无法使用 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();
    }
    }
    

    【讨论】:

    • 谢谢你...你救了我的命。它工作得很好...... :) 你能告诉我你是怎么知道哪个 ComponentName/path 将适用于 VoiceSearchPreferences 的。因为我也花了很多精力来解决它,但没有成功。再次感谢..!!!
    • @pargat 这是很多试验和错误...我的设备上有一个有用的应用程序,名为“Package Explorer”,它显示了可用的活动和组件的详细信息。得手帮我解决如何显示这些设置很好。 link
    • 这在姜饼之后不起作用。 stackoverflow.com/questions/11860229/…
    • 我不知道果冻豆的变化,谢谢。但是以上应该在所有 Honeycomb 和 ICS 设备上都可以正常工作吗?我有很多用户/测试人员确认... +适用于我所有的测试设备
    • 这将适用于 JellyBean stackoverflow.com/questions/11860229/…987654323@之后 Jelly bean 之前的所有设备
    猜你喜欢
    • 1970-01-01
    • 2018-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多