How to show up the settings for text to speech in my app?

后端 未结 4 942
生来不讨喜
生来不讨喜 2020-12-06 05:20

I have an application which uses the tts engine in Android, now as the activity starts, I want to show to the users the settings present in the phone for the tts engine in w

4条回答
  •  失恋的感觉
    2020-12-06 06:08

    I have merged Bandreid's and Force's answer to support every Android Version.

    Use this code:

    //Open Android Text-To-Speech Settings
    if (Build.VERSION.SDK_INT >= 14){
        Intent intent = new Intent();
        intent.setAction("com.android.settings.TTS_SETTINGS");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }else {
        Intent intent = new Intent();
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.TextToSpeechSettings"));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
    

    Or in one line:

    //Open Android Text-To-Speech Settings
    startActivity(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));
    

    Hope my answer help!

提交回复
热议问题