Skip to content Skip to sidebar Skip to footer

Taking Photo/video And Attaching To Email In Android

My app has functionality for allowing the user to either select a photo or video from their current library, or to take a new one, and then attach to an email. It seems to be worki

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_SENDIntent, 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 contentUri. 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"