3

I am trying to open the android default TTS settings whenever I click on the particular preference in my App settings. My pref_settings.xml looks like this:

     <PreferenceScreen
    android:key="Lang_Select"
    android:title="Language"
    android:summary="Select a Language">

</PreferenceScreen>

This is my list in android settings. and my SettingsActivity.java looks like this:

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);

}

public static class ChatSettingsFragment extends PreferenceFragmentCompat {

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        addPreferencesFromResource(R.xml.pref_settings);


    }
}

@Override
public void onBackPressed() {
    super.finish();
}

}

How can I start the android default TTS settings whenever the language button is clicked?

Thanks.

  • usually, you can start the settings via: `startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);` . For different action types see here:https://developer.android.com/reference/android/provider/Settings.html. I guess what you need is `ACTION_VOICE_INPUT_SETTINGS` but I have not tested it.... – Opiatefuchs Nov 20 '16 at 11:38
  • @Opiatefuchs I am new to this thing. So can you please help me out with defining the onClickListener for the preference list? Where shall I add the code to start an intent? – Anant Prasad Nov 20 '16 at 17:17
  • I tried, look at my answer.... – Opiatefuchs Nov 20 '16 at 17:33

2 Answers2

0

I have not worked with PreferenceFragmentCombat only with normal PreferenceFragment, but I guess it´s not that much difference in the basic implementations. So please, be noticed that this is maybe not the answer for your problem, but I try to help you a little bit and have to show some code. I have done it in my onCreate() method like this:

public class PreferenceFragment extends android.preference.PreferenceFragment {

private Preference mYourPreference;

        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preference_layout);

//initialize your preference with the key you used in xml layout
mYourPreference=(Preference)getPreferenceManager().findPreference(yourPreferenceKey);    

//set on click listener
mYourPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {

//start the activity
startActivity(new Intent(android.provider.Settings.ACTION_VOICE_INPUT_SETTINGS), 0);
                return true;
            }
        });

    }
}

I don´t know if ACTION_VOICE_INPUT_SETTINGS will work, just try it.

Opiatefuchs
  • 9,800
  • 2
  • 36
  • 49
  • @ Opiatefuchs Thanks a lot for the help. The above code solved my purpose of opening android voice settings. – Anant Prasad Nov 20 '16 at 17:57
  • I used intent.setComponent( new ComponentName("com.android.settings","com.android.settings.S‌​ettings$InputMethodA‌​ndLanguageSettingsAc‌​tivity" )); to open up language and input settings but for text to speech I am unable to find anything. – Anant Prasad Nov 20 '16 at 18:11
  • look what i have found, maybe it helps: http://stackoverflow.com/questions/3160447/how-to-show-up-the-settings-for-text-to-speech-in-my-app – Opiatefuchs Nov 20 '16 at 18:25
  • 2
    Try "com.android.settings.TTS_SETTINGS" as action, working on OS >= 5 – Harsh kurra Jan 06 '18 at 08:18
0

Try this:

startActivity(Intent("com.android.settings.TTS_SETTINGS"))

See: https://cs.android.com/android/platform/superproject/+/master:cts/apps/CtsVerifier/src/com/android/cts/verifier/speech/tts/TtsTestActivity.java;l=21?q=TTS_SETTINGS

drakeet
  • 2,685
  • 1
  • 23
  • 30