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 which they can change the pitch, test the engine,开发者_C百科 etc which is already present in the emulator.
So, how do I present to them this screen?
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);
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);
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!
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.
精彩评论