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

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

问题描述

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

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://...


推荐答案

我想你可能已经发现了一个bug (或至少不必要的限制)在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或另一个电子邮件客户端或手机挂载外部存储在其他地方。

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天全站免登陆