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. 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. I have implemented TTS settings successfully by using following code:

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...

最佳回答

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:正如在评论中指出的,谷歌搜索应用的Jelly Bean版本已经改变了。 抓住你可能利用的新问题。 您可以按照这些思路使用:

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();
}
}
问题回答

@brandall的回答对我来说是第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:最新组成部分名称





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签