gpt4 book ai didi

android - RecognizerIntent 不工作; "missing extra calling_package"

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:51:28 25 4
gpt4 key购买 nike

我在 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);

看起来应该可以,搜索弹出窗口在设备上显示“未知问题”,并在日志中显示:

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

看起来问题是缺少额外的“calling_package”;在 RecognizerIntent 页面上,它指出这个额外的是:

The extra key used in an intent to the speech recognizer for voice search. Not generally to be used by developers. The system search dialog uses this, for example, to set a calling package for identification by a voice search API. If this extra is set by anyone but the system process, it should be overridden by the voice search implementation.

据我所知,我不需要覆盖这个额外的东西,那么为什么我会收到这个错误?如何修复我的代码?

最佳答案

我遇到了完全相同的问题。我正在处理在我正在处理的 Activity 中具有 android:launchMode="singleInstance"的现有代码。这不适用于语音识别器 Intent 。我将其更改为 android:launchMode="standard"。现在让我们看看它如何破坏我程序的其余部分:)

关于android - RecognizerIntent 不工作; "missing extra calling_package",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4718643/

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