Sharing an unsaved image

94 views Asked by At

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?

1

There are 1 answers

0
romtsn On

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.