Show up the settings for text to speech in my app

I have implemented the TTS support for reading the Text Strings in my Application, and that works just fine. What I want to achieve is, that the user is able to Open the Preferences for TTS and can make changes according to his/her wish.

Here's my code

Intent intent = new Intent();
intent.setAction("com.android.settings.TTS_SETTINGS");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
DetailActivity.this.startActivity(intent);

But my app crash when running that code. I'm using android 4.1.2 device.

Anyone any suggestions?

Thanks in advance.

Upvotes: 2

Views: 289

Answers (1)

Aldo Wachyudi
Aldo Wachyudi

Reputation: 18001

You may use this intent action to check TTS preference

private void checkTTSAvailability() {
    Intent checkTtsIntent = new Intent();
    checkTtsIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkTtsIntent, TTS_DATA_CHECK_CODE);
}

And handle the result on onActivityResult(int requestCode, int resultCode, Intent data)

    if(requestCode == TTS_DATA_CHECK_CODE){
        // Success! File has already been installed
        if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){
            mTts = new TextToSpeech(getActivity(), this);
        }else{
            // fail, attempt to install tts
            Intent installTts = new Intent();
            installTts.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installTts);
        }
    }

or if you simply just want to open Settings just use this action

Intent intent = new Intent();
intent.setAction("com.android.settings.TTS_SETTINGS");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);

About that crash its probably because of ICS (API >= 14), use the solution above for ICS and up.

Upvotes: 2

Related Questions