1

I'm trying another approach for this problem: Share image without WRITE_EXTERNAL_STORAGE?

My idea is to encode a PNG in the data URI scheme. My code:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write("data:image/png;base64,".getBytes());
Base64OutputStream base64 = new Base64OutputStream(baos, Base64.NO_WRAP);
boolean ok = bitmap.compress(Bitmap.CompressFormat.PNG, 0, base64);
base64.close();
if (ok) {
    Uri uri = Uri.parse(baos.toString());
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/png");
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(intent);
}

The applications I've tried (e.g. Gmail on Android 4.4.4) say they cannot open the image. Do I create my Uri correctly? If so, what prevents other applications from reading my image?

Community
  • 1
  • 1
0xF
  • 3,214
  • 1
  • 25
  • 29

1 Answers1

-2

Do I create my Uri correctly?

I have no idea.

If so, what prevents other applications from reading my image?

Because they have no idea what to do with a data Uri.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491