2012-12-21 19 views
3

我想從我的應用發送電子郵件。所以我使用了下面的代碼。ACTION_SENDTO不起作用

String uriText = "[email protected]" + "?subject=" + URLEncoder.encode("Subject") + "&body=" + URLEncoder.encode("some text here"); 
Uri uri = Uri.parse(uriText); 
Intent sendIntent = new Intent(Intent.ACTION_SENDTO); 
sendIntent.setData(uri); 
startActivity(Intent.createChooser(sendIntent, "Send Email")); 

我配置了我的Gmail和EMail應用程序。我測試了我的Nexus S(果凍豆)和HTC T-Mobile G2(薑餅)。他們都顯示「沒有應用程序可以執行此操作」。

有沒有人有想法這裏有什麼問題?

回答

9

如果你要使用ACTION_SENDTO,該Uri應該使用mailto:smsto:方案。所以,試試mailto:[email protected]

+0

@KarthikPalanivelu:我不明白。如果「正常活動」是選擇器,則應該自行消失。如果「正常活動」是你的活動,你可以'完成()'使其消失。如果「正常活動」是另一回事,那麼對此你可能無能爲力。 – CommonsWare

+0

謝謝..它工作完美。 –

+0

真的很抱歉。這是我的一個簡單的錯誤。我不得不在休息時聲明。所以,它執行了下面的代碼,並啓動了另一個ACTION_SEND活動。我馬上注意到,馬上刪除了評論。感謝您的回覆:) –

7

如果你正在使用Intent.setData發送電子郵件,然後更改您的代碼爲:

String uriText = "mailto:[email protected]" + 
       "?subject=" + URLEncoder.encode("Subject") + 
       "&body=" + URLEncoder.encode("some text here"); 
Uri uri = Uri.parse(uriText); 
Intent sendIntent = new Intent(Intent.ACTION_SENDTO); 
sendIntent.setData(uri); 
startActivity(Intent.createChooser(sendIntent, "Send Email")); 
+0

感謝您的代碼:) –