调用 android.speech.RecognizerIntent API 会导致连接错误对话框,并在日志中显示“calling_package”警告

2024-03-31

我编写了一个小应用程序,允许用户通过按钮选择使用语音搜索的语言,而不是依赖用户的语言偏好(有时您希望用日语进行语音搜索,而不将整个 UI 切换为日语)。

我正在我的 HTC Desire /Android 2.1 (Softbank-x06ht) 上测试该应用程序。但是,当我调用语音 api 时,出现“连接失败”对话框 [重试/取消],并且 LogCat 显示此警告:

09-12 11:26:13.583: INFO/RecognitionService(545): ssfe url=http://www.google.com/m/voice-search
09-12 10:49:45.683: WARN/RecognitionService(545): required parameter 'calling_package' is missing in IntentAPI request

请注意,我可以使用 Google 语音搜索应用程序,并且它可以正常工作。

根据 API 文档http://developer.android.com/reference/android/speech/RecognizerIntent.html#EXTRA_CALLING_PACKAGE http://developer.android.com/reference/android/speech/RecognizerIntent.html#EXTRA_CALLING_PACKAGE开发人员不得使用calling_package 参数。那么,如果是这样的话,为什么日志说它丢失了呢?

我尝试自己提供参数,但它根本没有改变结果。

 private static final String TRIVOICE_CALLING_PACKAGE = "calling_package";
 private void callSpeechWebSearch (String language) {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,
            language);
    intent.putExtra(TRIVOICE_CALLING_PACKAGE,
            "org.filsa.trivoice");

    //intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
    try {
        startActivity(intent);         
    } catch (ActivityNotFoundException anfe) {
     makeToast("ANFE:" +anfe.getMessage());
    }
}

使用此代码获取您的包名称

intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                context.getPackageName());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

调用 android.speech.RecognizerIntent API 会导致连接错误对话框,并在日志中显示“calling_package”警告 的相关文章

随机推荐