2012-04-24 61 views
7

每次我創建從我的應用程序發送電子郵件的動作時間發送,它會提示很多選項,包括QR客戶端...ACTION_SEND力與電子郵件

有沒有辦法來強制僅通過電子郵件客戶端發送?

代碼發送電子郵件

String rec[] = { owner.email }; 
i = new Intent(Intent.ACTION_SEND); 
i.setType("text/plain"); 
i.putExtra(android.content.Intent.EXTRA_EMAIL, rec); 
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "RE: " + desc); 
i.putExtra(android.content.Intent.EXTRA_TEXT, 
     "\n\n\nSent from Mojo for Android"); 
startActivity(i); 

截圖,當我推出這個 screenshot

+0

閱讀本文http://stackoverflow.com/a/5802670/599993 – jzafrilla 2012-07-12 08:03:19

回答

24

嘗試會發生什麼的setType message/rfc822代替text/plain

+1

它顯示藍牙也與Gmail ...如何避免這種情況? – RAJESH 2013-04-19 10:15:28

+2

有沒有辦法縮小範圍以強制它使用Gmail發送? – 2013-07-25 16:55:18

+0

如果我必須使用我的附件(文件)類型的setType? +1,如果我只需要發送文本 – 2013-09-02 08:12:52

4

我想你應該改變setType

i.setType("message/rfc822") ; 
+0

是的,這默認爲在我的應用程序中打開Gmail。謝謝! – 2013-07-25 18:13:47

+0

它打開更多的應用程序,而不僅僅是電子郵件......,爲什麼不'text/html? – 2015-01-09 16:12:35

4
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
emailIntent.setType("text/html"); 
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
new String[] { "[email protected]" }); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
        "Subject of the Mail"); 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
          "This is my sample Mail"); 
emailIntent.setType("vnd.android.cursor.dir/email"); 
startActivity(Intent.createChooser(emailIntent, "Email:")); 

否則,你正在使用ACTION_SENDtext/plain類型使用它將只顯示了郵件客戶端,

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
emailIntent.setType("message/rfc822"); 
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
new String[] { "[email protected]" }); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
        "Subject of the Mail"); 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
          "This is my sample Mail"); 
//emailIntent.setType("vnd.android.cursor.dir/email"); 
startActivity(Intent.createChooser(emailIntent, "Email:")); 
0

長,它會顯示所有的有效選項。但是,如果您願意,您可以設計自己的對話窗口,通過編程方式進行過濾,從而僅顯示Gmail或其他郵件客戶端。

順便說一句,爲什麼你甚至需要這個窗口,當你只是想使用Gmail?

+0

如果我記得正確,你不能強制Gmail作爲默認的電子郵件客戶端 – thepoosh 2012-04-24 08:40:46

+0

nop,我要求你在自己定製的對話窗口中顯示Gmail – waqaslam 2012-04-24 08:45:42

+1

我不想強迫我的用戶使用特定的電子郵件客戶端。這似乎不是一個好主意。 – thepoosh 2012-04-24 09:12:28

-1
String rec[] = { owner.email }; 
i = new Intent(Intent.ACTION_SEND); 
i.setType("message/rfc822") ; 
i.putExtra(android.content.Intent.EXTRA_EMAIL, rec); 
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "RE: " + desc); 
i.putExtra(android.content.Intent.EXTRA_TEXT, 
     "\n\n\nSent from Mojo for Android"); 
startActivity(i); 

試試這個; :::

0
Intent intent = new Intent(); 
intent.setAction(Intent.ACTION_VIEW); 
intent.setData(Uri.parse("mailto:?to=email&subject=hello&body=hello%20world")); 
startActivity(Intent.createChooser(intent, "Send via...")); 

你可以試試這個:::::

0
Intent.setType("plain/text"); 

起初,當我立刻發現這一點,我雖然是一個錯誤,它的意思是text/plain,但這實際上是在應用程序列表中僅顯示電子郵件客戶端的正確方法。

試一試,看看你自己。

-1

將Intent.setType設置爲:Intent.setType(「plain/text」)正是如何強制android.content.Intent.ACTION_SEND調出電子郵件客戶端。完美而簡單的解決方案。謝謝!

+0

這不僅是垃圾郵件,而且是不正確的。你可以從我的問題中看到 – thepoosh 2013-03-24 07:39:32