Fix TTS init failure on Xiaomi (MIUI): add for TTS_SERVICE in AndroidManifest
Symptom: In my QRCode scan app, TextToSpeech init failed on a Xiaomi phone (China MIUI ROM) — status=-1 for engine com.google.android.tts, completely silent. The same APK worked fine on a Realme phone.
What I ruled out first:
- Media volume was on, in-app TTS toggle was on.
- Xiaomi's "Text-to-speech output": preferred engine was Google TTS, language Chinese (Taiwan), and the system "Listen to an example" test played sound fine — the engine itself was healthy.
- Explicitly specifying Google TTS and adding an engine fallback list both failed the same way (system default was already Google, nothing to fall back to).
Root cause: Android 11+ package visibility. Since API 30, an app cannot see — and therefore cannot bind — another app's service unless it declares the intent in <queries>. Google TTS is a third-party app providing a TTS service; without the declaration, binding the TTS engine is silently blocked and TextToSpeech init returns ERROR (-1). Some OEM ROMs (e.g. Realme) don't enforce this strictly, which is why the same APK worked there.
Fix — add to AndroidManifest.xml:
<queries>
<intent>
<action android:name="android.intent.action.TTS_SERVICE" />
</intent>
</queries>
After adding this (shipped as v1.1), TTS worked on both Xiaomi and Realme.
Lesson: whenever your app binds a service provided by another app (TTS engine, etc.) on Android 11+, declare the matching <queries> entry — otherwise the bind fails silently on strict OEM ROMs.