【发布时间】:2015-03-28 16:38:43
【问题描述】:
我正在尝试另一种方法来解决这个问题:Share image without WRITE_EXTERNAL_STORAGE?
我的想法是在data URI scheme 中编码一个PNG。我的代码:
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);
}
我尝试过的应用程序(例如 Android 4.4.4 上的 Gmail)说它们无法打开图像。
我是否正确创建了我的Uri?如果是这样,是什么阻止了其他应用程序读取我的图像?
【问题讨论】:
标签: android