androidkotlinandroid-jetpack-composetext-to-speechandroid-instant-apps

Text-To-Speech is not working in instant app in android Kotlin


I have an application that supports Text-To-Speech and it's worked fine in the installed app but when I tried to run instant then it's not working.

My question is whether the instant app is supported by Text-To-Speech or not.


Solution

  • The TextToSpeech class uses the intent android.intent.action.TTS_SERVICE under the hood.

    The Android Compatibility Definition Document gives us good indications which restrictions Instant Apps have regarding managing intents:

    3.15. Instant Apps

    [C-1-2] Instant Apps MUST NOT interact with installed apps via implicit intents unless one of the following is true:

    • The component's intent pattern filter is exposed and has CATEGORY_BROWSABLE
    • The action is one of ACTION_SEND, ACTION_SENDTO, ACTION_SEND_MULTIPLE
    • The target is explicitly exposed with android:visibleToInstantApps

    [C-1-3] Instant Apps MUST NOT interact explicitly with installed apps unless the component is exposed via android:visibleToInstantApps.

    Given that information, we can now inspect the app which is used by the Android OS by default for providing TTS functionality, which is the application com.google.android.tts.
    By downloading the APK file end decompiling it, we can inspect the manifest.xml file. In there, we find the following declaration mapped to the TTS_SERVICE intent:

    <service 
        android:label="0x7f14002a" 
        android:name="com.google.android.apps.speech.tts.googletts.service.GoogleTtsService" 
        android:exported="true" android:directBootAware="true">
        <intent-filter android:priority="100">
            <action android:name="android.intent.action.TTS_SERVICE"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
        <meta-data android:name="android.speech.tts" android:resource="0x7f170018"/>
    </service>
    

    You can see that neither of the conditions mentioned in the Android CDD is fulfilled:

    There is a dedicated list which intents are guaranteed to be supported on Instant Apps, which does not contain the TTS intent.

    So unfortunately, you will not be able to use TTS in Instant Apps by default. This would only possible if you installed a TTS Engine on your device that explicitly sets android:visibleToInstantApps="true".