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?