如何在Android应用程序中发送邮件附加文件? [英] How to Attach files with sending mail in android application?

查看:131
本文介绍了如何在Android应用程序中发送邮件附加文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过我的申请发送邮件。
为了我使用以下代码。

  Intent i = new Intent(Intent.ACTION_SEND); 
i.setType(text / plain);
i.putExtra(Intent.EXTRA_EMAIL,new String [] {recipient@example.com});
i.putExtra(Intent.EXTRA_SUBJECT,电子邮件主题);
i.putExtra(Intent.EXTRA_TEXT,body of email);
try {
startActivity(Intent.createChooser(i,Send mail ...));
} catch(android.content.ActivityNotFoundException ex){
Toast.makeText(MyActivity.this,没有安装电子邮件客户端),Toast.LENGTH_SHORT).show();
}

它工作正常,但我想附加一个xml文件。
有可能吗?如何?

解决方案

已经有很多类似的问题,在Stack Overflow中提供了完美的解决方案。



您可以查看几个:这里这里此处



解决方案是使用电子邮件意图:一个 putExtra与Key-Extra_Stream和Value-uri文件



请浏览常见问题解答,以确定如何从网站更好地了解。


I am sending mail through my application. For that I am using following code.

    Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

It just work fine but i want to attach an xml file with it. Is it possible? How?

解决方案

There are lots of similar questions asked with perfect solution in Stack Overflow already.

You can have look to few : here and here and here

Solution is to use with email intent : one more putExtra with Key-Extra_Stream and Value-uri to file.

And please go through the FAQ to undersatand How to better benifit from the site.

这篇关于如何在Android应用程序中发送邮件附加文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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