I am using the following code to detect whether TTS engines are installed on my device or not.
To launch the page to the TTS engine list:
//Open Android Text-To-Speech Settings
startActivityForResult(Build.VERSION.SDK_INT >= 14 ?
new Intent().setAction("com.android.settings.TTS_SETTINGS").setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) :
new Intent().addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("com.android.settings", "com.android.settings.TextToSpeechSettings")).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
,ConstantParams.VOICE_TTS_CHECK_CODE);
On returning to my app's activity:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == ConstantParams.VOICE_TTS_CHECK_CODE)
{
Log.d("TTS","Result code : "+resultCode);
if(resultCode != TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){
Log.d("TTSService","Valid TTS not installed");
Intent install = new Intent();
install.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(install);
}
else
{
//Do something
}
}
}
However, although my device has multiple TTS engines installed (I am able to manually go to that settings page, and change the TTS engine and verify the change in voice), this code is always returning a resultCode with value 0 (CHECK_VOICE_DATA_FAIL).
Please let me know how to make this check pass. And how to get the event on returning from the TTS settings page back to my app activity? (currently if I suppress the resultcode check, I am able to go to the TTS settings page from my app, but I am not able to detect the return phase back to my app's activity)