简体   繁体   English

针对 Android 11 时 SpeechRecognizer 不可用

[英]SpeechRecognizer not available when targeting Android 11

While testing an application after increasing the targetLevel to 30, I found that the SpeechRecognizer is not available any more, ie SpeechRecognizer.isRecognitionAvailable() always return false.虽然测试增加了targetLevel 30后的应用程序,我发现SpeechRecognizer没有提供任何更多,即SpeechRecognizer.isRecognitionAvailable()总是返回false。

If I set the targetLevel back to 29, without changing anything else, it is available again.如果我将 targetLevel 设置回 29,而不更改任何其他内容,则它再次可用。 This happens on a real device (Pixel 3a) and the emulator.这发生在真实设备(Pixel 3a)和模拟器上。

It doesn't seem to be a behaviour change .这似乎不是行为改变 The only requirement mentioned by the Recognizer API is the Manifest.permission.RECORD_AUDIO Recognizer API 提到的唯一要求是Manifest.permission.RECORD_AUDIO

I also found no clue in the logcat.我在 logcat 中也没有发现任何线索。

I finally found a solution.我终于找到了解决方案。

Trying to actually use the (allegedly not available) recognizer lead to this message in the logcat :尝试实际使用(据称不可用)识别器会导致 logcat 中出现此消息:

10-13 09:19:50.273  1531  1799 I AppsFilter: interaction: PackageSetting{eb6a1b2 my.application.package/10225} -> PackageSetting{ab34503 com.google.android.googlequicksearchbox/10140} BLOCKED
10-13 09:19:50.273  1531  1799 W ActivityManager: Unable to start service Intent { act=android.speech.RecognitionService cmp=com.google.android.googlequicksearchbox/com.google.android.voicesearch.serviceapi.GoogleRecognitionService } U=0: not found
10-13 09:19:50.273 25348 25348 E SpeechRecognizer: bind to recognition service failed

So the problem seems to be related to this new Android 11 "feature" , and the solution was to add a query to the manifest for the blocked intent :所以问题似乎与这个新的 Android 11“功能”有关,解决方案是向清单中添加一个查询来阻止意图:

<manifest ...>
    <queries>
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM