Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, i.e. SpeechRecognizer.isRecognitionAvailable() always return false.

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.

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

I also found no clue in the logcat.

like image 366
bwt Avatar asked Oct 12 '20 13:10

bwt


People also ask

Is speechrecognizer available at targetlevel 30?

Bookmark this question. Show activity on this post. 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. If I set the targetLevel back to 29, without changing anything else, it is available again.

How will Android 11 affect my app?

Like earlier releases, Android 11 includes behavior changes that may affect your app. The following behavior changes apply exclusively to apps that are targeting Android 11 or higher. If your app sets targetSdkVersion to 30, you should modify your app to support these behaviors properly, where applicable.

Does the speech recognition function work with uselegacy unchecked?

The Speech Recognition function does not work with "UseLegacy" unchecked. I created an app with UseLegacy unchecked today and it does not work. I can't get result from the function. If I check the UseLegacy checkbox, it works. *The Google dialog pop up. this with UseLegacy unchecked.

Can I use non-SDK interfaces on Android 11?

If your app does not target Android 11, some of these changes might not immediately affect you. However, while you can currently use some non-SDK interfaces ( depending on your app's target API level ), using any non-SDK method or field always carries a high risk of breaking your app.


1 Answers

I finally found a solution.

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

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>
like image 174
bwt Avatar answered Sep 21 '22 12:09

bwt