gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 12:58:21 26 4
gpt4 key购买 nike

我写了一个小应用程序,允许用户通过按钮选择他使用哪种语言进行语音搜索,而不是依赖于用户的语言偏好(有时你想用日语进行语音搜索,而不用将整个用户界面切换为日语) .

我正在我的 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 文档 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());

关于android - 调用 android.speech.RecognizerIntent API 导致连接错误对话框,在日志中显示 'calling_package' 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3693480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com