1

我的应用程序正在发送带有附件的电子邮件,但问题是它发送电子邮件但没有附件。该文件确实存在于 SD 卡中,我可以将其分离并查看该文件。

这是代码Email.java

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, new String[] { "" });
i.putExtra(Intent.EXTRA_SUBJECT, "");
i.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://mnt/sdcard/fun/itisfun.csv"));    
i.putExtra(Intent.EXTRA_TEXT, "");
i.setType("message/rfc822");
startActivity(Intent.createChooser(i,"gmail :"));

这是我在Menifest中尝试过的权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<permission  android:name="android.permission.INTERNET"></permission>

我会感谢你的帮助。

4

4 回答 4

6

尝试如下:

       File pngDir = new File(Environment.getExternalStorageDirectory(),"fun/"); 
            if (!pngDir.exists())
            {
                pngDir.mkdirs();
            }              
            File pngfile=new File(pngDir,"itisfun.csv");
            Uri pngUri =Uri.fromFile(pngfile);
            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("text/plain");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{""});
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
            emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,pngUri);
            emailIntent.setType("message/rfc822");
            startActivity(Intent.createChooser(emailIntent, "Send mail..."));
于 2013-01-25T13:25:40.067 回答
0

这是我用来将文件附加到电子邮件(Gmail 应用程序)的代码:

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
        emailIntent.setType("message/rfc822");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
            new String[]{emailTo});
        //has to be an ArrayList
        ArrayList<Uri> uris = new ArrayList<Uri>();
        //convert from paths to Android friendly Parcelable Uri's
        for (String file : filePaths)
        {
            File fileIn = new File(file);
            Uri u = Uri.fromFile(fileIn);
            uris.add(u);
        }
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailText);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subject);
        emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        context.startActivity(Intent.createChooser(emailIntent, "Send mail via"));
于 2013-01-25T13:25:04.170 回答
0

试试这个代码:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailSignature);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, toSenders);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subjectText);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, messageText+"\n\n"+emailSignature); 

emailIntent.setType("image/jpeg");
File bitmapFile = new File(Environment.getExternalStorageDirectory()+
        "/"+FOLDER_NAME+"/picture.jpg");
myUri = Uri.fromFile(bitmapFile);
emailIntent.putExtra(Intent.EXTRA_STREAM, myUri);
startActivity(Intent.createChooser(emailIntent, "Send your email in:"));

希望它会帮助你。

于 2013-01-25T13:26:21.643 回答
0

试试下面的代码

                Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("text/plain");
                i.putExtra(Intent.EXTRA_EMAIL, new String[] { "" });
                i.putExtra(Intent.EXTRA_SUBJECT, "");
                i.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://sdcard/fun/itisfun.csv"));    
                i.putExtra(Intent.EXTRA_TEXT, "");
                i.setType("message/rfc822");
                startActivity(Intent.createChooser(i,"gmail :"));
于 2013-01-25T13:27:30.467 回答