3

我编写了一个小应用程序,允许用户通过按钮选择他使用语音搜索的语言,而不是依赖用户的语言偏好(有时您希望在不将整个 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 Voice Search 应用程序,它可以正常工作。

根据 API Docs 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());
    }
}
4

2 回答 2

2

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

intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                context.getPackageName());
于 2013-05-10T11:10:44.097 回答
1

我遇到了同样的问题,并将调用包设置为实际的调用包(不是类),然后一切正常。Tmobile G2 上的 Android 2.2。

于 2010-12-09T20:58:38.933 回答