android - 使用默认的 Android 应用程序(内置电子邮件应用程序)在 Android 中发送电子邮件

标签 android android-intent

我想使用默认的 Android 电子邮件应用程序从我的应用程序发送电子邮件。我已经为此编写了代码

Intent mailIntent = new Intent(android.content.Intent.ACTION_SEND);
mailIntent.setType("plain/text");
mailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { EMAIL });
mailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Invitation");
mailIntent.putExtra(android.content.Intent.EXTRA_TEXT,MAIL_MESSAGE);
startActivity(mailIntent);

但这里正在打开电子邮件应用程序。我想发送邮件而不是开始任何 Activity 。有没有办法替代startActivity并启动intent Action ?

请帮助我。

提前致谢。

最佳答案

this link可能有用,看看 another useful link或来自 this link 的代码 fragment 附在下面

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);  

emailIntent.setType("plain/text");  
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, newString[]{"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="542d3b212639353d3814233136273d20317a373b39" rel="noreferrer noopener nofollow">[email protected]</a>"});  
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mySubject);  

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, myBodyText);  

startActivity(Intent.createChooser(emailIntent, "Send mail));  

希望有帮助...

关于android - 使用默认的 Android 应用程序(内置电子邮件应用程序)在 Android 中发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9805250/

相关文章:

android - 在 Android Fragment 上发布静态引用

android - 如何在没有菜单按钮的情况下使用选项菜单?

android - 如何在 Baseactivity 和子 Activity 中处理 butterknife 绑定(bind)?

java - 如何从另一个应用程序重定向到我的应用程序

android - 保持按钮可见性的实例状态

android - 通过 Intent 启动 Mx Player

Android:使用 Context.startService 与 PendingIntent.getService 启动服务

java - 尝试将 FFmpeg 与 NDK 一起使用时出现 UnsatisfiedLinkError

android - 向位置管理器添加多个接近警报

Android: float 操作按钮以透明背景显示