Search code examples
androidemailandroid-intentandroid-image

How to share both text and image in the share intent (email and gmail)


I would like to make a share button for both gmail and the rom email app . The problem is how to share both image and text?

For the image , I can provide either file uri / bitmap / whatever need and I only need to share one image.

   final Intent result = new Intent(android.content.Intent.ACTION_SEND);
    result.setType("plain/text");
    result.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { recipient });
    result.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    result.putExtra(android.content.Intent.EXTRA_TEXT, body);

Thanks for helping


Solution

  • You can find ans from below code:

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
    emailIntent.setType("image/jpeg");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {""}); 
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, EMAIL_SUBJECT); 
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, EMAIL_BODY);
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+fileName));
    startActivity(Intent.createChooser(emailIntent, "Sharing Options"));
    

    Hope this helps..