2010-07-01 51 views
10

我有一個應用程序,它使用Android中的tts引擎,現在當活動開始時,我想向用戶展示手機中存在的設置,以便他們可以改變音調,測試引擎等等的tts引擎。這已經存在於仿真器中。如何在我的應用程序中顯示文本到語音的設置?

那麼,我該如何向他們展示這個屏幕?

回答

9

我對我的應用程序有同樣的問題,發現這篇文章。我設法自己做,所以這個答案適用於那些可能需要它的人。

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); 

我們創建一個明確的意圖,我們必須啓動com.android.settings.TextToSpeechSettings組件。 您可以在eclipse中使用LogCat來查找您嘗試啓動的任何軟件包或組件。只需查看ActivityManager的Starting活動消息,就可以看到任何Activity的包和組件名稱。

UPDATE

就Android ICS的你應該使用的是部隊貼在下面的解決方案。

intent = new Intent(); 
intent.setAction("com.android.settings.TTS_SETTINGS"); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
this.startActivity(intent); 
+1

看來這個版本不再工作了(至少在三星注2(API 18))。儘管來自部隊的答案仍然有效。 ''' intent = new Intent(); intent.setAction(「com.android.settings.TTS_SETTINGS」); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent);''' – Jani 2016-02-04 11:58:11

+0

謝謝@Jani。我更新了我的答案以指向Force的解決方案。 – Bandreid 2016-02-04 12:34:48

2

創建一個意圖打開設置。我認爲這將是。

Intent i = new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SETTINGS); 
startActivityForResult(i); // to come back to your activity. 
+0

謝謝,但這會給用戶鍵盤設置。我想顯示這個屏幕是在設置 - >文本到語音。這裏是屏幕截圖:http://picasaweb.google.com/113593639172348814875/ScreenShots#5489006879503683298 – pranay 2010-07-01 18:31:28

16

對於ICS用戶,Bandreid的電話將不再工作。你必須使用此代碼:

intent = new Intent(); 
intent.setAction("com.android.settings.TTS_SETTINGS"); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
this.startActivity(intent); 
3

我已經合併Bandreid的部隊回答支持所有Android版本

使用此代碼:

//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); 
} 

或者在同一行:

//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)); 

希望我的回答幫助!

相關問題