我正在尝试共享使用共享 Intent 保存到内部存储的图像文件。 在我 Intent 图像文件不显示之后。
我用下面的代码来保存图像文件
try {
FileOutputStream fos = openFileOutput("twitterimage.jpg", Context.MODE_PRIVATE);
// Writing the bitmap to the output stream
bikeBm.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
} catch (Exception e) {
Log.e("saveToInternalStorage()", e.getMessage());
}
//Intent 代码
File internalFile = getFileStreamPath("twitterimage.jpg");
Uri uri = Uri.fromFile(internalFile);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM,new File(uri));
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));
当我使用上面的“uri”检查文件是否存在时,图像文件存在 在内部存储中,但使用检查文件
String file = "data/data/com.bike.app/twitterimage.jpg";
File f = new File(file);
显示文件不存在。
请帮我解决这个问题。
最佳答案
如果我猜对了,您想在应用程序之间共享图像。您的问题是您在编写文件时使用了 Context.MODE_PRIVATE
,因此其他应用程序无法访问该文件。
要分享图片,您可以使用 MediaProvider限制对您的媒体的访问或简单地使用 Context.MODE_WORLD_READABLE
但该文件将是公开可读的。
希望对你有帮助
关于java - Android分享意向分享图片不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14253708/