安卓:将文件从设备内存的电子邮件 [英] Android:Attach file with email from device memory

查看:107
本文介绍了安卓:将文件从设备内存的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我希望能够发送电子邮件。我能够用文本方式发送电子邮件。不过,我想增加从电子邮件设备内存中附加文件或照片。没有任何人对我怎么能做到这一点任何想法?

In my application, I want to be able to send email. I am able to send email with text. However, I want to add attach file or photo from device memory in email. Does anybody have any ideas on how can I do this?

推荐答案

下面是做电子邮件与文件附件的演示。

Here is the demo of doing "Email with file attachment".

注意:下面code正在保存你的SD卡内,并添加作为附件的电子邮件文件。

Note: Below code is taking file stored inside your sd-card and add as an attachment to the email.

try 
   {        
       String fileName = URLEncoder.encode(yourfilename, "UTF-8");
       String PATH =  Environment.getExternalStorageDirectory()+"/"+fileName.trim().toString();

       Uri uri = Uri.parse("file://"+PATH);
       Intent i = new Intent(Intent.ACTION_SEND);
       i.setType("text/plain");
       i.putExtra(Intent.EXTRA_EMAIL, "");
       i.putExtra(Intent.EXTRA_SUBJECT,"android - email with attachment");
       i.putExtra(Intent.EXTRA_TEXT,"");
       i.putExtra(Intent.EXTRA_STREAM, uri);
       context.startActivity(Intent.createChooser(i, "Select application"));
   } 
   catch (UnsupportedEncodingException e) 
   {
        // TODO Auto-generated catch block
        e.printStackTrace();
   }

这篇关于安卓:将文件从设备内存的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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