0

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)

SoulRayder
  • 5,072
  • 6
  • 47
  • 93
  • That's not the correct Intent - see here http://stackoverflow.com/a/25723262/1256219 – brandall Mar 09 '17 at 22:02
  • It does not redirect to the TTS screen with the intent you used, however, I modified mine removing the setflag call and I was able to redirect to the TTS screen. However, I am still getting the CHECK_VOICE_DATA_FAIL result code when I return back from that screen. – SoulRayder Mar 10 '17 at 14:10
  • If you run the linked test code and the list is empty, you'll know there are no engines installed - you could then redirect your users to the Play Store. To check if something else is wrong, use this intent http://stackoverflow.com/a/10912091/1256219 The one you are using doesn't supply a callback. – brandall Mar 11 '17 at 02:38
  • The second link you gave now is allowing me to choose between available TTS engines only the first time I try to access it. The second time (or any further attempts), it directly detects the CHECK_VOICE_DATA_PASS event without allowing me to choose. Is there some "flag" that I can reset, so that the options to choose between available TTS engines appears everytime I try to access it? Also, in the code in the second link, you have used "protected" instead of "public", so my IDE was complaining. Was that intentional use of "protected" over "public"? – SoulRayder Mar 11 '17 at 13:46
  • Did you accidentally select 'always choose this option' - if so, you can clear it from the chosen app's settings 'clear defaults'. Protected vs Private vs Public depends on the scope you intend to use it in http://stackoverflow.com/q/215497/1256219 – brandall Mar 12 '17 at 20:21

0 Answers0