Android - 无法在电子邮件中附加文件 [英] Android - not able to attach a file in email

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

问题描述

默认情况下,保存到内部存储的文件对您的应用程序是私有的,其他应用程序无法访问它们(用户也不能).

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

我能够在 DDMS 的文件浏览中看到文件/data/data/package_name/files/",但是当我在电子邮件中使用 imageUri 附加上述文件 URI 时,我看到该附加文件的大小为 0kb.我使用了 Android 的默认电子邮件 API.

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?

虽然我成功地将文件保存在 SD 卡中并从 SD 卡附加文件,但这工作正常.

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

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

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

推荐答案

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

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:

每个与 Android 兼容的设备都支持共享的外部存储",您可以使用它来保存文件.这可以是可移动存储介质(例如 SD 卡)或内部(不可移动)存储.

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.

这意味着您完全不必担心设备没有外部存储.尽管如此,外部存储有时仍不可用.请参阅 http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

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