定位Android 11时,SpeechRecognizer不可用 [英] SpeechRecognizer not available when targeting Android 11

查看:107
本文介绍了定位Android 11时,SpeechRecognizer不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将targetLevel增加到30后测试应用程序时,我发现SpeechRecognizer 不再可用,即 SpeechRecognizer.isRecognitionAvailable()总是返回false.

While testing an application after increasing the targetLevel to 30, I found that the SpeechRecognizer is not available any more, i.e. SpeechRecognizer.isRecognitionAvailable() always return false.

如果我将targetLevel设置回29,而未进行任何其他更改,则它将再次可用.这是在真实设备(Pixel 3a)和仿真器上发生的.

If I set the targetLevel back to 29, without changing anything else, it is available again. This happens on a real device (Pixel 3a) and the emulator.

这似乎不是行为更改.Recognizer API提到的唯一要求是 Manifest.permission.RECORD_AUDIO

It doesn't seem to be a behaviour change. The only requirement mentioned by the Recognizer API is the Manifest.permission.RECORD_AUDIO

我在logcat中也没有发现任何线索.

I also found no clue in the logcat.

推荐答案

我终于找到了解决方案.

I finally found a solution.

尝试实际使用(据说不可用)识别器导致logcat中出现此消息:

Trying to actually use the (allegedly not available) recognizer lead to this message in the 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

因此问题似乎与此新版Android 11有关.功能" ,解决方案是向清单添加针对被阻止的意图的查询:

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 :

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

这篇关于定位Android 11时,SpeechRecognizer不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆