0

I want to share an image which is fresh created and therefore unsaved. It's stored in a Bitmap object. In the send binary content article you need to have an URI to the image: shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);

But is it somehow possible to share the image without saving it first?

principal-ideal-domain
  • 3,998
  • 8
  • 36
  • 73

1 Answers1

0

You can use this code:

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    yourBitmapObj.compress(Bitmap.CompressFormat.JPEG, 75, bos);
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType("image/jpeg");
    intent.putExtra(Intent.EXTRA_STREAM, bos.toByteArray());
    startActivity(Intent.createChooser(intent, "Send to"));

But if you want to share via popular apps, like Instagram, as I know they are trying to parse Uri but not getting the ByteArray, and you will receive exceptions from apps.

romtsn
  • 11,704
  • 2
  • 31
  • 49