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

后端 未结 4 932
生来不讨喜
生来不讨喜 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:01

    Create an Intent to open the settings. I think it would be.

    Intent i = new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SETTINGS);
    startActivityForResult(i); // to come back to your activity.
    
    0 讨论(0)
  • 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!

    0 讨论(0)
  • 2020-12-06 06:11

    I had the same problem for my app and found this post. I managed to do it by myself so this answer is for those who might need it as well.

    ComponentName componentToLaunch = new ComponentName(
            "com.android.settings",
            "com.android.settings.TextToSpeechSettings");
    Intent intent = new Intent();
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setComponent(componentToLaunch);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    

    We create an explicit intent, and we have to launch the com.android.settings.TextToSpeechSettings component. You can use LogCat in eclipse to find whatever package or component you are trying to launch. Just look at the ActivityManager's Starting activity messages and you will see the package and component name of any Activity.

    UPDATE

    As of Android ICS you should use the solution that the Force posted below.

    intent = new Intent();
    intent.setAction("com.android.settings.TTS_SETTINGS");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    this.startActivity(intent);
    
    0 讨论(0)
  • 2020-12-06 06:20

    For ICS users Bandreid's call won't work anymore. You have to use this code:

    intent = new Intent();
    intent.setAction("com.android.settings.TTS_SETTINGS");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    this.startActivity(intent);
    
    0 讨论(0)
提交回复
热议问题