Taking Photo/video And Attaching To Email In Android
Solution 1:
Are there changes I can make to my code to allow for a more universal solution to this?
Sure. Get rid of getPath()
.
It seems to be working on the majority of devices and Android versions.
Not really.
Use the Uri
properly. It is not a file. Even in the few cases where it does point to a file, you may not have access to that file via the filesystem.
You say that you are using this for an email attachment. If that is ACTION_SEND
with a EXTRA_STREAM
extra, use the Uri
that you were given. Add FLAG_GRANT_READ_URI_PERMISSION
on the ACTION_SEND
Intent
, so that the read permissions that you were granted get sent along to the ACTION_SEND
handler.
If you are using something else for the email, use a ContentResolver
and openInputStream()
to get an InputStream
on the file
or content
Uri
. Then, either pass that stream to the other code, or use that stream to make your own local file copy (e.g., in getCacheDir()
), and then use that local copy, deleting it when you do not need it.
Post a Comment for "Taking Photo/video And Attaching To Email In Android"