Android:Folder有许多图像,但通过gallery intent只能看到单个图像
我使用以下简单方法通过应用程序保存图像字节:Android:Folder有许多图像,但通过gallery intent只能看到单个图像,android,image,android-intent,android-gallery,Android,Image,Android Intent,Android Gallery,我使用以下简单方法通过应用程序保存图像字节: public static boolean StoreBytesToFile(byte[] messagebytes, String FilePathName) { try { FileOutputStream fos = new FileOutputStream(FilePathName); fos.write(messagebytes); fos.flush(); f
public static boolean StoreBytesToFile(byte[] messagebytes, String FilePathName)
{
try
{
FileOutputStream fos = new FileOutputStream(FilePathName);
fos.write(messagebytes);
fos.flush();
fos.close();
}
catch(java.io.FileNotFoundException fnfe)
{
return false;
}
catch(java.io.IOException ioe)
{
return false;
}
return true;
}
然后,当用户想要查看存储的图像时,我使用gallery intent打开它:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file://" + m_ImageFilename);
intent.setDataAndType(uri, "image/*");
startActivity(intent);
但是,gallery仅显示由m_ImageFilename
指向的单个图像文件,尽管同一文件夹中存储了其他图像
因此,画廊意图的实际行为如下:
虽然预期的行为是这样的:
作为一个重要提示,我必须指出,重新启动手机后,gallery intent会按预期显示文件夹中的所有图像。此外,从果冻豆到棉花糖的所有版本的行为都是相同的
所以,每次保存图像后,用户必须重新启动手机,以便通过gallery intent查看文件夹中的所有图像
请有人告诉我这里遗漏了什么,如何修复?您需要将保存的图像添加到gallery。。。我会帮你的。谢谢你。我试过这个方法。创建文件,将其添加到gallery中,并以gallery view意图打开。然而,我发现它并不总是有效的。在我的例子中,它在我第二次查看文件时起作用。此外,这还产生了其他问题(例如,尽管我调用了
getContentResolver().delete
,但图像仍然显示在gallery中)。我发现有很多关于这些函数的讨论,但没有找到完美的解决方案。