我有以下代码:
FileOutputStream out = null;
try {
out = new FileOutputStream("/sdcard/tmp/i.jpg");
b.compress(Bitmap.CompressFormat.JPEG, 90, out);
Toast.makeText(getApplicationContext(), "Succeded", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Failed", Toast.LENGTH_LONG).show();
}
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("/sdcard/tmp/i.jpg"));
startActivity(Intent.createChooser(share, "Share image"));
当它被调用时,一切正常。该文件已保存,并弹出选择器。但是一旦你进入你选择的活动,它们都会弹出一条消息,说我无法添加该图像。除了GMail,它工作正常。那么我该怎样做才能解决这个问题呢?
答案 0 :(得分:1)
我没有看到任何关闭FileOutputStream
的代码。也许这是问题的原因?保存图像后尝试调用out.close()
。
更新:
也尝试使用完整的图像路径,即尝试像这样做:
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/tmp/i.jpg"));