识别器内容不起作用; "缺少额外的calling_package"

Isa*_*ler 4 android speech-recognition

我在Android 2.2上使用RecognizerIntent API时遇到问题.当我使用此代码调用API时:

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
startActivityForResult(intent, REQUEST_CODE_VOICE_SEARCH);
Run Code Online (Sandbox Code Playgroud)

看起来它应该工作,搜索弹出窗口在设备上和日志中说"未知问题":

01-17 14:25:30.433: ERROR/RecognitionActivity(9118): ACTION_RECOGNIZE_SPEECH intent called incorrectly. Maybe you called startActivity, but you should have called startActivityForResult (or otherwise included a pending intent).
01-17 14:25:30.433: INFO/RecognitionControllerImpl(9118): startRecognition(#Intent;action=android.speech.action.RECOGNIZE_SPEECH;launchFlags=0x800000;component=com.google.android.voicesearch/.IntentApiActivity;B.fullRecognitionResultsRequest=true;S.android.speech.extra.LANGUAGE_MODEL=free_form;end)
01-17 14:25:30.433: INFO/RecognitionControllerImpl(9118): State change: STARTING -> STARTING
01-17 14:25:30.443: ERROR/RecognitionControllerImpl(9118): required extra 'calling_package' missing in voice search intent
01-17 14:25:30.443: ERROR/RecognitionControllerImpl(9118): ERROR_CLIENT
01-17 14:25:30.443: ERROR/RecognitionControllerImpl(9118): ERROR_CLIENT
Run Code Online (Sandbox Code Playgroud)

看起来问题是缺少"calling_package"额外的; 在RecognizerIntent页面上,它声明这个额外的是:

用于语音识别器的意图用于语音搜索的额外密钥.通常不被开发人员使用.例如,系统搜索对话框使用它来设置一个呼叫包,以便通过语音搜索API进行识别.如果除系统进程之外的任何人设置此额外内容,则应由语音搜索实现覆盖它.

据我所知,我不需要覆盖这个额外的,所以为什么我得到这个错误?我该如何修复我的代码?

小智 6

我有同样的问题.我正在处理我正在处理的活动中具有android:launchMode ="singleInstance"的现有代码.这对于语音识别器意图不起作用.我把它改成了android:launchMode ="standard".现在让我们看看它如何打破我程序的其余部分:)