使用BroadcastReceiver intent查询SpeechRecognizer支持的语言

时间:2011-10-23 23:35:32

标签: android broadcastreceiver speech-recognition

使用SpeechRecognizer.ACTION_GET_SUPPORTED_LANGUAGES查询支持的语言时遇到问题。

private void queryLanguages() {
    Intent i = new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS);
    sendOrderedBroadcast(i, null);
}

现在,我知道它说在BroadcastizerIntent.DETAILS_META_DATA中指定了BroadcastReceiver,但我不确定如何访问它。

基本上我要问的是如何创建一个Intent来检索可用的语言数据?

1 个答案:

答案 0 :(得分:2)

这是如何完成的:

    Intent intent = new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS);
    context.sendOrderedBroadcast(intent, null, new HintReceiver(),
                    null, Activity.RESULT_OK, null, null);

    private static class HintReceiver extends BroadcastReceiver {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (DBG)
                    Log.d(TAG, "onReceive(" + intent.toUri(0) + ")");
                if (getResultCode() != Activity.RESULT_OK) {
                    return;
                }
                // the list of supported languages. 
                ArrayList<CharSequence> hints = getResultExtras(true)
                        .getCharSequenceArrayList(
                                RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES);

        }
    }

注意:

  

这些是否实际提供取决于具体实施