5

I'm in the process of implementing an instant app that makes use of the Text to Speech functionality available on Android devices. I have managed to get a TextToSpeech instance initialized and working correctly for non-instant apps by following the instructions detailed in the Android dev blog post An introduction to Text-To-Speech in Android

I have refactored my app to be an instant app and have confirmed that the Text to Speech functionality is working in the non-instant app. However when running the following ACTION_CHECK_TTS_DATA intent in the instant app:

val checkIntent = Intent()
checkIntent.action = TextToSpeech.Engine.ACTION_CHECK_TTS_DATA
activity.startActivityForResult(checkIntent, initilizeTtsRequestCode)

I get the following error:

FATAL EXCEPTION: main
 Process: [PACKAGE_NAME_REDACTED], PID: 9500
 java.lang.RuntimeException: Unable to start activity ComponentInfo{[PACKAGE_NAME_REDACTED]/[PACKAGE_NAME_REDACTED].ui.SNTMainActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.speech.tts.engine.CHECK_TTS_DATA }
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
     at android.app.ActivityThread.-wrap11(Unknown Source:0)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
     at android.os.Handler.dispatchMessage(Handler.java:105)
     at android.os.Looper.loop(Looper.java:164)
     at android.app.ActivityThread.main(ActivityThread.java:6541)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
  Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.speech.tts.engine.CHECK_TTS_DATA }
     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1936)
     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1615)
     at android.app.Activity.startActivityForResult(Activity.java:4472)
     at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:65)
     at android.app.Activity.startActivityForResult(Activity.java:4430)
     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:711)
     at [PACKAGE_NAME_REDACTED].SNTTtsManager.initialize(SNTTtsManager.kt:92)
     at [PACKAGE_NAME_REDACTED].ui.SNTMainActivity.onStart(SNTMainActivity.kt:96)
     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1333)
     at android.app.Activity.performStart(Activity.java:6992)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2780)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
     at android.app.ActivityThread.-wrap11(Unknown Source:0) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
     at android.os.Handler.dispatchMessage(Handler.java:105) 
     at android.os.Looper.loop(Looper.java:164) 
     at android.app.ActivityThread.main(ActivityThread.java:6541) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

I can't find any information about Text to Speech or similar system services not being available to Instant Apps on the Restricted features page nor FAQ. Is this a bug or is this feature not available to Instant Apps?

TheIT
  • 11,919
  • 4
  • 64
  • 56
  • Have you tried this on a regular app on the same device/emulator? May not even be related to instant-apps. See https://stackoverflow.com/questions/3674362/getting-error-when-loading-tts and https://stackoverflow.com/questions/2786399/intentnotfoundexception-for-texttospeech-engine-action-install-tts-data – TWL Aug 04 '17 at 23:28
  • Thanks for the comment and links @TWL, I can confirm it works when I run the code in a non-instant app environment – TheIT Aug 07 '17 at 02:08
  • 1
    I tested this on my Nexus 5X and like you, it works when on a regular app. But when I run it on an instant-app, I don’t see your error, I see `java.lang.SecurityException: Not allowed to start activity Intent { act=android.speech.tts.engine.CHECK_TTS_DATA }` This would suggest that TTS is not supported, but if you believe otherwise, then file a bug and link to it back in here! https://issuetracker.google.com/issues/new?component=316045&template=1018787 – TWL Aug 07 '17 at 21:40
  • 1
    I have the same issue, I believe it's not currently supported by Instant Apps (at least as of Jan 10, 2018). `Caused by: java.lang.SecurityException: Setting tts_default_synth is not accessible from ephemeral package [.....]` For now, I've eliminated the TTS functionality from my Instant App: private void initTextToSpeech() { if (InstantApps.isInstantApp(this)) { mIsTtsSupported = false; return; } mTextToSpeech = new TextToSpeech(this, this::checkTtsResult); } – prerak Jan 11 '18 at 07:49

1 Answers1

0

Android Instant Apps is relatively new, there is a section in Restricted Features that tells you the unsupported features:

  • Unsupported features
  • Long-running background services
  • Manifest-registered broadcast receivers
  • Externally accessible content providers
  • Re-engagement notifications
  • Content providers

And I believe that TextToSpeech is either an externally accessible content provider or a Long-running background service.

Hugo sama
  • 899
  • 1
  • 9
  • 19
  • Thanks for the response, however Text to Speech is neither an external content provider nor a long running background service, at least not given the standard definitions of those terms – TheIT Aug 03 '17 at 02:58