2010-11-17 75 views
1

我想發送一封意向郵件。如何通過Android中的Intent發送郵件?

我想以編程方式打開一個對話框,顯示處理此Intent的不同程序並讓用戶顯示他最喜歡的郵件程序。在程序中,我想指定一個標題,一個接收者和一個消息體。

你能舉個例子說明如何做到這一點嗎?

回答

4

使用下面的代碼通過一個Intent發送電子郵件:

Intent intent = new Intent(Intent.ACTION_SEND); 
intent.setType("plain/text"); 
intent.putExtra(Intent.EXTRA_EMAIL,new String[] { "[email protected]" }); 
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject of the mail"); 
intent.putExtra(Intent.EXTRA_TEXT, "body of the mail"); 

startActivity(Intent.createChooser(intent, "Title of the chooser dialog"));