I'm trying to share an image I have previously saved on disk, sending an Intent.ACTION_SEND
. The problem is that I can't find a way to be compatible with different apps, official Gmail app and TweetDeck in my case.
The image I want to share is contained in a File
:
File agendaFile;
// its path using getAbsolutePath() -> /data/data/com.mypackage/files/agenda.jpg
Option A) using Uri.fromFile
Uri agendaUri = Uri.fromFile(agendaFile);
// the value -> file:///data/data/com.mypackage/files/agenda.jpg
Results
- Gmail, is the image attatched to the email? NO
- Tweetdeck, is the image added to the tweet message? YES
Option B) using Uri.parse
Uri agendaUri = Uri.parse(agendaFile.toURI().toString());
// the value -> file:/data/data/com.mypackage/files/agenda.jpg
Results
- Gmail, is the image attatched to the email? YES
- Tweetdeck, is the image added to the tweet message? NO
Finally
In both cases I send the intent like this:
final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("image/jpg");
intent.putExtra(android.content.Intent.EXTRA_STREAM, agendaUri);
startActivity(Intent.createChooser(intent, "title"));
So, is there any other options to share an image? How is it the best way to share an image being compatible with most apps as possible?
Thanks!
this code is more easy
I finally solved the problem storing the image at the MediaStore. Instead of using the URI of the File what I do is:
And finally I use
contentUriFile
:try
for me it works for twitter, whatsapp, bluetooth....
EDIT: full code:
For me using FileProvider worked out. I had it set up for taking photos with built-in camera and used it for sharing (see below).