1

I'm trying to share a file using the something like intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); the file is located in the path data/data/my.package.name/folder/fileName and whenever I try to send the file using the Gmail app I get an error.

I think this is due to the read permissions of the file, and my question is how can give the intent access to the file, without having to copy the file to another location.

Thanks

user557240
  • 273
  • 5
  • 15
  • Can you post your logcat error for us? – Jared Burrows Jan 13 '13 at 17:38
  • There not much too see in the logcat. I'm able to open up Gmail and the file is added as an attachment but when I get a notification saying the attached failed. I've playing around with the code, will check for a log cat error. But I don't think there was one. – user557240 Jan 13 '13 at 17:42
  • Are you trying to open a file from another applications data path other than your own? That is against Android's security model. – Jared Burrows Jan 13 '13 at 17:45
  • Sorry there was indeed a log cat error. I get the following when clicking send: `Failed to attached file:///data/data/com.mypackage/a/folder/filename` due to FileNotFoundException. Since the cached file has already been tired, this file cannot be attached.` Hence why I thought it was a file permission error. – user557240 Jan 13 '13 at 17:46
  • No the file in my data path. I want to use an intent to allow gmail to send the file, however its not working. – user557240 Jan 13 '13 at 17:48
  • @user557240 read my answer that would help you to send file on gmail. – Ajay S Jan 13 '13 at 17:49
  • possible duplicate of [Create and Share a File from Internal Storage](http://stackoverflow.com/questions/12170386/create-and-share-a-file-from-internal-storage) – rds Feb 09 '15 at 12:12

2 Answers2

3

Try this it might help you.

You are trying to send the file as an email attachment using intents.

The reason why the file is empty is that the email app does not have access to the file in data/data/my.package.name/folder/fileName, due to Androids security model (the data/data/my.package.name/folder/fileName directory is private to your app).

To attach file on email in android you have to save the files first in external memory.

Ajay S
  • 48,003
  • 27
  • 91
  • 111
  • Yes, I thought this would be the case. So is there no other solution other than using external memory? – user557240 Jan 13 '13 at 17:50
  • Alright thanks. In the docs I did see that you can use `openFileOutput("filename", MODE_WORLD_READABLE);` so I'll just have to copy the data in the file. Then delete it. Thanks – user557240 Jan 13 '13 at 17:53
  • @user557240 Yes Its can not be in case of to send file to email. – Ajay S Jan 13 '13 at 17:56
1

The standard mechanism to share content is via the ContentProvider. http://developer.android.com/training/enterprise/app-compatibility.html#sharing_files

rds
  • 26,253
  • 19
  • 107
  • 134