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

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

问题描述

在我的应用程序文件写入到内部存储器为覆盖在 Android开发。再后来我想以电子邮件,我写到内部存储器中的文件。这是我的code,我得到的错误,任何帮助将AP preciated。

 的FileOutputStream FOS = openFileOutput(xmlFilename,MODE_PRIVATE);
fos.write(xml.getBytes());
fos.close();
意向意图=新的意图(android.content.Intent.ACTION_SEND);
intent.setType(text / plain的);
...
开放的我们的uri = Uri.fromFile(新文件(xmlFilename));
intent.putExtra(android.content.Intent.EXTRA_STREAM,URI);
startActivity(Intent.createChooser(意向,发送电子邮件..));
 

和错误的是

  

文件://附件路径必须指向文件:// MNT / SD卡。忽略附件文件:// ...

解决方案

我想你可能已经发现在Android的Gmail客户端中的错误(或者至少是不必要的限制)。我能解决它,但它给我的印象太具体实施,并且需要更多一点的工作可移植的:

首先CommonsWare是非常正确的有关需要,使文件全局可读:

  FOS = openFileOutput(xmlFilename,MODE_WORLD_READABLE);
 

接下来,我们需要解决的Gmail就坚持了到/ mnt / SD卡(或执行特定的相同呢?)路径:

 开放的URI = Uri.fromFile(新文件(到/ mnt / SD卡/../.."+ getFilesDir()+/+ xmlFilename));
 

至少我修改姜饼设备上,这让我的Gmail附件从私有存储到自己,并使用preVIEW按钮,当我收到它看到的内容。但我不觉得很好,他们不得不这样做,使其工作,谁知道会与其他版本的Gmail或其他电子邮件客户端或手机,它在其他地方挂载外部存储发生什么。

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.."));

And the error is

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

解决方案

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:

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

fos = openFileOutput(xmlFilename, MODE_WORLD_READABLE);

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));

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