I am trying to launch an Intent to send an email. All of that works, but when I try to actually send the email a couple 'weird' things happen.
here is code
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/jpeg");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Photo");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/dcim/Camera/filename.jpg"));
sendIntent.putExtra(Intent.EXTRA_TEXT, "Enjoy the photo");
startActivity(Intent.createChooser(sendIntent, "Email:"));
So if I launch using the Gmail menu context It shows the attachment, lets me type who the email is to, and edit the body & subject. No big deal. I hit send, and it sends. The only thing is the attachment does NOT get sent.
So. I figured, why not try it w/ the Email menu context (for my backup email account on my phone). It shows the attachment, but no text at all in the body or subject. When I send it, the attachment sends correctly. That would lead me to believe something is quite wrong. Do I need a new permission in the Manifest launch an intent to send email w/ attachment? What am I doing wrong?
From RFC 1738 section 3.10:
A file URL takes the form:
where host is the fully qualified domain name of the system on which the path is accessible, and path is a hierarchical directory path of the form directory/directory/.../name.
So it's file:///path/from/root just like http://host/path/from/root because there's an implicit 'localhost' between the second and third slash. But as mentioned above, use Uri.FromFile() to build it.
I have got solution on this after 4 days, Please note following points while giving path to File class in Android(Java):
1) Use path for internal storage String path="/storage/sdcard0/myfile.txt";
2) path="/storage/sdcard1/myfile.txt";
3) mention permissions in Manifest file.
4) First check file length for confirmation.
5) Check paths in ES File Explorer regarding sdcard0 & sdcard1 is this same or else......
e.g.
I had the same symptoms. In my case it was because I was initially saving the attachment with the permissions
MODE_PRIVATE
. As soon as I changed it toMODE_WORLD_READABLE
it seems GMail was then able to access the file and send the attachment properly.See more
instead of "Uri.parse" use "Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"file name"))"
Environment.getExternalStorageDirectory() - path to SDcard or any other external storage
It appears that this is actually correct, not sure what was happening, but after a reboot it started working :/
Also getting the same problem
Code:
From adb logcat:
Looks like the email provider is attaching a 0 length file. When I check the filesystem the file is there and correct. The code which creates the image file is well finished prior to the attempt to email it.
Anyone fixed this without magic reboots (I've already tried that)?
Regards,
Fin
Update
Path for me should have been
file:///sdcard/DumbDumpers/DumbDumper.jpg
you need the extra
/
as this points to the root directory, i.e.:file://
+/sdcard/DumbDumpers/DumbDumper.jpg
combined as
file:///sdcard/DumbDumpers/DumbDumper.jpg
In the above snippet you need:
I hope this helps. It took me ages to debug.
Regards,
Finlay