电子邮件的意图总是默认启动Gmail [英] Email intent always launch gmail by default

查看:140
本文介绍了电子邮件的意图总是默认启动Gmail的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 字符串身体=消息;意图emailIntent =新意图(Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,看看这本书我读);
emailIntent.setType(纯/文);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,体);
startActivity(Intent.createChooser(emailIntent,发送电子邮件......));

不管我做什么(删除所有Gmail帐户和签到一个Hotmail帐户的邮件应用程序),这code推出的Gmail默认情况下,不显示或让我选择我的邮件通用的应用程序。

因此,有没有办法让用户通过Hotmail或其他邮件提供商发送电子邮件。

更新:
其实这是我这辈子遇到code最好的一块,它presents直接与您的应用程序选择器其中只有邮件客户端是present。下面的答案会给你一个巨大的应用程序列表来选择从是不相关的。

 字符串MAILTO =;
意图email_intent =新意图(Intent.ACTION_SENDTO,Uri.fromParts(电子邮件地址,邮寄地址,NULL));
email_intent.putExtra(android.content.Intent.EXTRA_SUBJECT主题的文字在这里);
email_intent.putExtra(android.content.Intent.EXTRA_TEXT,这里正文);startActivity(Intent.createChooser(email_intent,发送电子邮件......));


解决方案

尝试使用正确的MIME类型(文本/纯),而不是一个无效的MIME类型(纯/文)。

String body="message";

Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Check out this book I am reading");  
emailIntent.setType("plain/text");  
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);  
startActivity(Intent.createChooser(emailIntent, "Send email..."));

No matter what I do (removing all gmail accounts and signin a hotmail account with mail app), this code launches Gmail by default and do not show or let me choose my universal mail app.

Consequently, there is no way to let user send email via hotmail or other mail provider.

update: Actually this is the best piece of code I ever come across, it presents you directly with an app chooser where only mail client are present. The answer below will give you a huge list of apps to choose from that are irrelevant.

String mailTo="";
Intent email_intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",mailTo, null)); 
email_intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject text here");
email_intent.putExtra(android.content.Intent.EXTRA_TEXT,"Body text here"); 

startActivity(Intent.createChooser(email_intent, "Send email..."));

解决方案

Try using the correct MIME type (text/plain) instead of an invalid MIME type (plain/text).

这篇关于电子邮件的意图总是默认启动Gmail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆