呼叫android.speech.RECOGNIBERINTENT API导致连接错误对话框,显示“ calle_package”在日志中警告

StackOverflow https://stackoverflow.com/questions/3693480

  •  02-10-2019
  •  | 
  •  

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

我正在我的HTC Desire /Android 2.1(SoftBank-X06HT)上测试该应用程序。但是,当我调用语音API时,我会得到一个“连接失败”对话框[RETRY/CANCEL],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 开发人员不使用CALLE_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());
    }
}
有帮助吗?

解决方案

我遇到了相同的问题,并将呼叫软件包设置为实际的呼叫软件包(不是类),然后工作正常工作。 Tmobile G2上的Android 2.2。

其他提示

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

intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                context.getPackageName());
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top