2009-11-20 28 views

回答

27

試試這個snippet

/* Create the Intent */ 
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 

/* Fill it with Data */ 
emailIntent.setType("plain/text"); 
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"}); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject"); 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Text"); 

/* Send it off to the Activity-Chooser */ 
context.startActivity(Intent.createChooser(emailIntent, "Send mail...")); 

關鍵部分:使用EXTRA_EMAIL您的地址,並使用createChooser()的情況下,用戶配置了一個以上的電子郵件客戶端。

+3

謝謝,這工作:)我做過類似的嘗試,但它只是拉起了一些消息屏幕,而不是電子郵件應用程序。我認爲那是因爲當時我沒有在模擬器中設置電子郵件帳戶? – scuba 2009-11-20 22:09:42

+0

你使用了最終的關鍵字是什麼?這會導致我不知道的某種優化嗎? – Scott 2009-11-21 02:46:35

+0

我沒有寫這段代碼。就我個人而言,我可能不會在那裏使用final關鍵字。 – CommonsWare 2009-11-21 11:23:20

3

你嘗試

Intent intent = new Intent(
    Intent.ACTION_SENDTO, 
    Uri.parse("mailto:[email protected]") 
); 
startActivity(intent); 
+0

給了它一個鏡頭,仍然得到的消息: 不支持的操作 此操作當前不受支持。 在吐司般的泡沫。我需要在清單中設置一些東西來讓我的應用程序使用它嗎? – scuba 2009-11-20 20:06:43

1

我認爲這裏真正的問題是你在官方模擬器上運行,你的意圖不符合任何東西。

從我的測試中,這是一個當意圖的URI(來自setData())不匹配任何內容並且您在其中一個官方Android模擬器上運行時發生的問題。這似乎沒有發生在真實的設備上,所以它不應該是現實世界的問題。

您可以使用此代碼時,這是怎麼回事,你推出的意圖之前發生的檢測:

ComponentName emailApp = intent.resolveActivity(getPackageManager()); 
ComponentName unsupportedAction = ComponentName.unflattenFromString("com.android.fallback/.Fallback"); 
boolean hasEmailApp = emailApp != null && !emailApp.equals(unsupportedAction); 

(顯示「不支持操作」的操作方法是com.android.fallback.FallbackActivity活動的名稱)

相關問題