将XLS(Excel)文件附加到电子邮件

And*_*w S 3 email android attachment excellibrary

我的应用程序使用intent方法向用户发送电子邮件,这是导出Excel电子表格数据(由JExcell API创建)的便捷方式.

该文件包含在名为records的文件夹中的SD卡上.

我试图发送的文件是call measurments.xls.

我已经在代码中测试了在发送之前是否存在该文件.电子邮件编辑器显示附件,但是当我发送然后接收电子邮件时,附件不存在.

但是,如果我将excel文件替换为png图像,则会收到附件.那是什么给了??

下面是我用来发送电子邮件的代码,它只是一个类中的一个短暂的静态方法.

    public static  void sendEmailWithAttachment(Context ctx, String to,String subject, String message, String fileAndLocation)
    {
        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
        emailIntent.setType("text/plain");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {to}); 

        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,  subject); 
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,  message); 


          File file = new File(fileAndLocation);
         //  File file = getFileStreamPath();
           if (file.exists())
           {
               Log.v("Farmgraze", "Email file_exists!" );
           }
           else
           {
               Log.v("Farmgraze", "Email file does not exist!" );
           }


        Log.v("FarmGraze", "SEND EMAIL FileUri=" + Uri.parse("file:/"+ fileAndLocation));
        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/"+  fileAndLocation));

        ctx.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    }//end method
Run Code Online (Sandbox Code Playgroud)

那么我需要做什么来接收xls文件?更改方法代码第二行中的mime类型?如果是这样的话.任何有用的建议将不胜感激.

谢谢阅读.

A.
Run Code Online (Sandbox Code Playgroud)

And*_*w S 6

好的人只是为这个问题添加闭包我找到了解决方案.

问题是发送到URI的文件路径String需要有三个正斜杠.

如:

file:///sdcard/somefolder/some_file.xls.
Run Code Online (Sandbox Code Playgroud)

另外对于excel文档,需要设置类型如下:

emailIntent.setType("application/excel");
Run Code Online (Sandbox Code Playgroud)

所以这个问题是双管齐下的.我知道通过这个线程的三个斜杠解决方案,但因为它没有工作认为问题在于其他地方.

此外,我通过此网页了解了正确的mime类型,其中列出了所有支持的mime类型,并且可能对其他读者非常有用.

所以感谢您阅读并对我现在解决的小问题感兴趣.