本文介绍了可以打开"讲现在"对话框编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时可以打开现在讲对话框编程?

Is it possible to open the "Speak Now" dialog programmatically?

目前,如果用户点击我的搜索按钮,将打开一个对话框,我自动具有软键盘打开,因此用户并不需要挖掘文本编辑领域。

Currently, if the user taps my 'Search' button, a dialog opens and I have the soft keyboard open automatically so the user doesn't need to tap the textedit field.

我想提供一个替代语音搜索,将打开的对话​​框,并有请讲话窗口自动打开。因此用户不必找到并点按键盘上的话筒按钮。

I'd like to offer an alternate 'Search by voice' that will open the dialog and have the "Speak now" window open automatically. So the user doesn't have to find and tap the 'mic' button on the keyboard.

任何想法?

推荐答案

是的,这是可能的。看看 ApiDemos在Android SDK 样本。有一个名为活动 VoiceRecognition ,它利用的。

Yes, it is possible. Take a look at ApiDemos sample in the Android SDK. There is an activity named VoiceRecognition, it utilizes RecognizerIntent.

基本上,所有你需要做的是一个了解创建适当的意图与一些额外的,然后读取结果。

Basically, all you need to do is to craete a proper intent with some extras and then read the results.

private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;

private void startVoiceRecognitionActivity() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    // identifying your application to the Google service
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
    // hint in the dialog
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
    // hint to the recognizer about what the user is going to say
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                    RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    // number of results
    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
    // recognition language
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,"en-US");
    startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
        ArrayList<String> matches = data.getStringArrayListExtra(
                    RecognizerIntent.EXTRA_RESULTS);
        // do whatever you want with the results
    }
    super.onActivityResult(requestCode, resultCode, data);
}

这篇关于可以打开&QUOT;讲现在&QUOT;对话框编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:19