Android的 - 不能够附加文件的电子邮件 [英] Android - not able to attach a file in email

查看:244
本文介绍了Android的 - 不能够附加文件的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在默认情况下,保存在内部存储的文件是私有的,你的应用程序和其他应用程序不能访问它们(也能够为用户的)。

我能看到文件/数据/数据​​/程序包/文件/文件探讨DDMS,但是当我附加在电子邮件中使用imageUri上述文件的URI,然后我看到附加文件是0KB的。 我已经使用了Android的默认电子邮件的API。

任何人都可以给我建议,如何将一个文件中的电子邮件是私人的应用程序?

虽然我成功了能够保存在SD卡上的文件,并安装从SD卡的文件,这是工作的罚款。

但是,如果SD卡不可用并将文件保存到内部存储器,那我怎么才能将它们附加在电子邮件中。

 字符串文件名=hello_file.txt;
串串=世界,你好!的FileOutputStream FOS = openFileOutput(文件名,Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();

文件镜像文件= getFileStreamPath(文件名);
乌里imageUri = Uri.fromFile(镜像文件);

最终意图emailIntent =新的意图(android.content.Intent.ACTION_SEND);
emailIntent.setType(* / *);
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,imageUri);

this.startActivityForResult(Intent.createChooser(emailIntent,发送邮件...),SUB_ACTIVITY);
 

解决方案

当您尝试从内部存储附加文件,GMail的错误写入日志:

  ERROR / Gmail的(...):文件://附件的路径必须指向文件:/// MNT / SD卡。
 

电子邮件应用程序会告诉你,即使它没有实际存在附加的文件。

至于外部存储,文件说:

  

每一个Android兼容设备支持共享外部存储,你可以用它来保存文件。这可以是一个可移动存储介质(如SD卡)或内部(不可移动)的存储

这意味着你不必担心设备没有外部存储的。仍然,外部存储器可以是在时间不可用。请参照<一个href="http://developer.android.com/guide/topics/data/data-storage.html#filesExternal">http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user).

I am able to see the file "/data/data/package_name/files/ in file explore in DDMS, but when i attached the above file URI using imageUri in email , then i saw that attached file is of 0kb. i have used the default email APIs of Android.

Can anyone suggest me ,how to attach a file in email that is private to the application?

although i am successful able to save the file in SD card and attaching the file from SD card , this is working fine.

But if SD card is not available and saving the file to the internal storage , then how can i attach them in email.

String FILENAME = "hello_file.txt";
String string = "hello world!";FileOutputStream fos = openFileOutput(FILENAME,     Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();

File imageFile = getFileStreamPath(FILENAME );
Uri imageUri = Uri.fromFile(imageFile);

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("*/*");
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,imageUri);

this.startActivityForResult(Intent.createChooser(emailIntent, "Send mail..."),SUB_ACTIVITY);

解决方案

When you try to attach file from internal storage, GMail writes an error to the log:

ERROR/Gmail(...): file:// attachment paths must point to file:///mnt/sdcard. 

E-mail application would show you the attached file even if it didn't physically exist.

As for an external storage, documentation says that:

Every Android-compatible device supports a shared "external storage" that you can use to save files. This can be a removable storage media (such as an SD card) or an internal (non-removable) storage.

That means you don't have to worry about device not having an external storage at all. Still, external storage can be unavailable at times. Refer to http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

这篇关于Android的 - 不能够附加文件的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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