如何在android中的电子邮件中附加单个文件?

时间:2012-11-06 05:52:04

标签: android email android-intent

  

可能重复:
  how to send email with attached file in android?

当我在收件箱中发送电子邮件而不是显示文件附件0字节时。我的代码如下。如何解决这个问题呢?提前谢谢你。

             String path = "/data/data/"
               + context.getApplicationContext().getPackageName()
               + "/files/";
             String filename= "save.ime";
             Intent mSendIntent = new Intent(
                android.content.Intent.ACTION_SEND);
        mSendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mSendIntent.setType("plain/text");
        mSendIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                new String[] { "" });
        mSendIntent.putExtra(android.content.Intent.EXTRA_CC, "");
        mSendIntent.putExtra(android.content.Intent.EXTRA_BCC, "");
        mSendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                "InfoMe Profile Request");
        mSendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new 
               File(path+filename)));
        mSendIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                Function.bodypart);
        context.startActivity(Intent.createChooser(
                mSendIntent, "Send mail..."));

1 个答案:

答案 0 :(得分:0)

试试这段代码:

filesend = new File("/data/data/"
           + context.getApplicationContext().getPackageName()
           + "/files/");
File filelocation = filesend ;
Intent mSendIntent = new Intent(Intent.ACTION_SEND);
mSendIntent.setType("image/jpeg");
mSendIntent.putExtra(Intent.EXTRA_EMAIL, "user@gmail.com" );
mSendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+filelocation.getAbsolutePath()));
startActivity(Intent.createChooser(mSendIntent, "Send email"));