2012-04-24 58 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