TTS crashing on some devices
<p>I am getting the following error when loading TTS on some devices (I don't know what they are because this is coming from a remote stacktrace from clients).</p>

<pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.droidprofessor.android.mmm/com.droidprofessor.android.mmm.ActivityGame}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.speech.tts.engine.CHECK_TTS_DATA }
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
       at android.app.ActivityThread.access$2200(ActivityThread.java:119)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:123)
       at android.app.ActivityThread.main(ActivityThread.java:4363)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:521)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
       at dalvik.system.NativeStart.main(Native Method) 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:1408)
       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
       at android.app.Activity.startActivityForResult(Activity.java:2749)
       at com.droidprofessor.android.mmm.ActivityTTS.onCreate(ActivityTTS.java:29)
       at com.droidprofessor.android.mmm.ActivityGame.onCreate(ActivityGame.java:96)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
       ... 11 more
</code></pre>

<p>AND</p>

<pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.droidprofessor.android.mmm/com.droidprofessor.android.mmm.ActivityGame}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.speech.tts.engine.CHECK_TTS_DATA }
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
       at android.app.ActivityThread.access$2200(ActivityThread.java:119)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:123)
       at android.app.ActivityThread.main(ActivityThread.java:4363)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:521)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
       at dalvik.system.NativeStart.main(Native Method)
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:1408)
       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
       at android.app.Activity.startActivityForResult(Activity.java:2749)
       at com.droidprofessor.android.mmm.ActivityTTS.onCreate(ActivityTTS.java:29)
       at com.droidprofessor.android.mmm.ActivityGame.onCreate(ActivityGame.java:96)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
       ... 11 more
</code></pre>

<p>In my previous post (http://stackoverflow.com/questions/3674362/getting-error-when-loading-tts) I made the changes as described.  I added the following</p>

<pre><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
                    Toast.makeText(getApplicationContext(), R.string.unable_to_access_the_android_market, Toast.LENGTH_LONG).show();
                } else {
                   startActivity( installIntent );
                }
</code></pre>

<p>Here is the full source of the TTS activity</p>

<pre><code>public abstract class ActivityTTS extends Activity implements OnInitListener {
    //TEXT TO SPEECH SERVICE
    public static final int CHECK_TTS_AVAILABILITY = 0;
    private static final String TAG = "ActivityTTS";
    private TextToSpeech mTts; //Text to speech library


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //TTS Service
        Intent checkIntent = new Intent();
        checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
        startActivityForResult(checkIntent, CHECK_TTS_AVAILABILITY);
    }

    /**
     * For TTS
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        try {
            if(Logging.DEBUG_LOG) Log.d(TAG, "TTS Response: "+requestCode);
            if (requestCode == CHECK_TTS_AVAILABILITY) {
                if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {

                    // success, create the TTS instance
                    mTts = new TextToSpeech(this, this);            

                } else {
                    // missing data, install it
                    Toast.makeText(getApplicationContext(), R.string.install_audio_data, Toast.LENGTH_LONG).show();

                    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
                        Toast.makeText(getApplicationContext(), R.string.unable_to_access_the_android_market, Toast.LENGTH_LONG).show();
                    } else {
                       startActivity( installIntent );
                    }

                    finish();
                }
            }
        }catch (Exception e) {
            if(Logging.ERROR_LOG) Log.e(TAG, "Unable to access service");
            finish();
        }

    }




    /**
     * Loads when the TTS is ready
     */
    @Override
    public void onInit(int status) {
        mTts.setLanguage(Locale.getDefault());
    }


    /**
     * Speak text
     */
    final void speak(String text) {
        try{
            mTts.stop(); //Stop speaking
            mTts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
        }
        catch(Exception e) {
            if (Logging.ERROR_LOG) Log.e(TAG, "TTS Failed - cannot say: "+text );
        }

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

        //Close the Text to Speech Library
        if(mTts != null) mTts.shutdown(); 
    }
}
</code></pre>
