2

可能重复:
如何在 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..."));
4

1 回答 1

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"));
于 2012-11-06T06:17:21.757 回答