Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntentNotFoundException for TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA

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.

like image 860
Casebash Avatar asked May 07 '10 05:05

Casebash


1 Answers

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.

like image 149
Karan Avatar answered Sep 27 '22 15:09

Karan