In my application’s main activity I issue an Intent with ACTION_CHECK_TTS_DATA:
Intent intent = new Intent();
intent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(intent, 0);
When it returns, in onActivityResult(), I try to list the available voices:
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
String availableVoices = intent.getStringExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
Log.d("TTS engine installed", "Available voices: " + availableVoices);
new TextToSpeech(this, this);
}
}
}
I am receiving CHECK_VOICE_DATA_PASS and everything works fine but according to the Log.d() message, intent.getStringExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES) returns null!
I know that there are quite a few voices in my phone, installed and working properly, so why does getStringExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES) return null?
What am I missing?
You are fetching the EXTRA_AVAILABLE_VOICES list using
getStringExtra()instead of getStringArrayListExtra().See this answer for more details.