I am trying to implement text to speech by following this article on the Android Developers Blog. It suggests the following code for installing text to speech data if it is not supported.
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
This throws an Exception
:
ActivityNotFoundException
: No activity found to handle Intent
However, I am using the code here to determine the the intent is actually supported. Here is the list representation:
[ResolveInfo{43cc5280 com.svox.pico.DownloadVoiceData p=0 o=0 m=0x108000}]
Why doesn't this work?
Update
I don't know why, but it seems to work now.
To check whether the intent is actually supported or not, use the following code :
PackageManager pm = getPackageManager();
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
ResolveInfo resolveInfo = pm.resolveActivity( installIntent, PackageManager.MATCH_DEFAULT_ONLY );
if( resolveInfo == null ) {
// Not able to find the activity which should be started for this intent
} else {
startActivity( installIntent );
}
If it is not able to find the activity using resolveActivity() then it means that the activity requires some other parameters which are not provided. In that case, you should get the class name using the queryIntentActivities() and set the intent component/class name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With