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
  • 2,593
  • 1
  • 21
  • 26

1 Answers1

-1

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
  • 954,112
  • 185
  • 2,315
  • 2,367