来自内部存储的电子邮件 [英] Email from internal storage

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

问题描述

在我的应用程序中,我将文件写入内部存储,如 安卓开发者.然后稍后我希望通过电子邮件发送我写入内部存储的文件.这是我的代码和我得到的错误,任何帮助将不胜感激.

On my application I write a file to the internal storage as covered on android developer. Then later on I wish to email the file I wrote into the internal storage. Here is my code and the error I am getting, any help will be appreciated.

FileOutputStream fos = openFileOutput(xmlFilename, MODE_PRIVATE);
fos.write(xml.getBytes());
fos.close();
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
...
Uri uri = Uri.fromFile(new File(xmlFilename));
intent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Send eMail.."));

错误是

file://附件路径必须指向 file://mnt/sdcard.忽略附件文件://...

file:// attachment path must point to file://mnt/sdcard. Ignoring attachment file://...

推荐答案

我想您可能已经发现了 Android Gmail 客户端中的一个错误(或者至少是不必要的限制).我能够解决它,但它让我觉得太特定于实现,并且需要更多的工作才能移植:

I think you may have found a bug (or at least unnecessary limitation) in the android Gmail client. I was able to work around it, but it strikes me as too implementation specific, and would need a little more work to be portable:

第一个 CommonsWare 关于需要使文件世界可读是非常正确的:

First CommonsWare is very much correct about needing to make the file world readable:

fos = openFileOutput(xmlFilename, MODE_WORLD_READABLE);

接下来,我们需要解决 Gmail 对/mnt/sdcard(或实现特定的等效?)路径的坚持:

Next, we need to work around Gmail's insistence on the /mnt/sdcard (or implementation specific equivalent?) path:

Uri uri = Uri.fromFile(new File("/mnt/sdcard/../.."+getFilesDir()+"/"+xmlFilename));

至少在我修改过的 Gingerbread 设备上,这让我可以将私人存储中的附件通过 Gmail 发送给我自己,并在我收到它时使用预览按钮查看内容.但我对必须这样做才能使其工作感到不太好",谁知道另一个版本的 Gmail 或另一个电子邮件客户端或将外部存储安装在其他地方的手机会发生什么.

At least on my modified Gingerbread device, this is letting me Gmail an attachment from private storage to myself, and see the contents using the preview button when I receive it. But I don't feel very "good" about having to do this to make it work, and who knows what would happen with another version of Gmail or another email client or a phone which mounts the external storage elsewhere.

这篇关于来自内部存储的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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