Search code examples
androidandroid-intentandroid-sharing

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?


Solution

  • 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:"));