Home > Back-end >  Why is Android 11 mandating INTENT_ACTION_TTS_SERVICE?
Why is Android 11 mandating INTENT_ACTION_TTS_SERVICE?

Time:12-28

Android developers reference states that:

Apps targeting Android 11 that use text-to-speech should declare TextToSpeech.Engine.INTENT_ACTION_TTS_SERVICE in the queries elements of their manifest:

 <queries>
   ...
  <intent>
      <action android:name="android.intent.action.TTS_SERVICE" />
  </intent>
 </queries>

I have my app working flawlessly with TextToSpeech on Android 11 and 13 without this clause in the manifest, so the obvious question is "why?":

  1. Why is this requirement?
  2. What would break if this requirement is not implemented?
  3. What would the app be gaining if I implement this requirement?

CodePudding user response:

The <queries> element adds items to the allowlist for package visibility. Package visibility constrains what PackageManager will return to your app when you try finding out information about other installed apps. This not only affects direct calls to PackageManager but other framework methods that in turn use PackageManager in your app's process.

I have not worked with TTS, but apparently something in TTS needs to use PackageManager to find TTS_SERVICE implementations. At least, that is the only justification that I can see for those instructions.

What would break if this requirement is not implemented?

Since you are not breaking now, my best guess is that you might not be able to use third-party TTS engines that tie into this framework. Even with the package visibility restrictions, PackageManager will return information about many pre-installed apps — the restriction mostly affects user-installed apps.

FWIW, I cover package visibility in Android 11 in this chapter of this free book.

  • Related