我正在开发一个 android 应用程序,我在其中实现了语音识别和 TTS。所以我想为谷歌语音识别和 TTS 启动设置屏幕,以允许用户从应用程序中更改设置。 我已经使用以下代码成功实现了 TTS 设置:
intent = new Intent();
intent.setAction("com.android.settings.TTS_SETTINGS");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
现在我想在我的应用程序中显示系统的“谷歌语音识别设置”以允许用户更改语言选项等。我已经搜索了很多...做了很多尝试但未能加载语音识别设置屏幕.请告诉我如何实现它。 提前致谢...
最佳答案
@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 - 如何在我的应用程序中显示谷歌语音识别设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8868410/