Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending text and Image simultaneously in Android

In my application, My requirement is to send Image and text simultaneously. So I use the following code

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_TEXT, "My photos");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///"+f));                       
startActivity(Intent.createChooser(share, "Share Image"));

But only the image is sended but the text is not sending. How can I solve this problem?

like image 958
Renjith Krishnan Avatar asked Mar 20 '26 09:03

Renjith Krishnan


2 Answers

plz try this

//assuming uris is a list of Uri

Intent intent = null;
if (uris.size > 1){
intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
} else if (uris.size() == 1) {
intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));}
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_TEXT, "Some message");
startActivity(Intent.createChooser(intent,"compatible apps:"));
like image 173
Jithu P.S Avatar answered Mar 22 '26 23:03

Jithu P.S


You are setting the MIME type of that Intent to image that's why only the image is sent. Something like this will solve your problem:

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("*/*");
share.putExtra(Intent.EXTRA_TEXT, "My photos");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///"+f));                       
startActivity(Intent.createChooser(share, "Share Image"));
like image 24
Kaushik Avatar answered Mar 22 '26 22:03

Kaushik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!