Android: Folder has many images but only single image is visible through gallery intent

138 Views Asked by At

I am saving image bytes through my application using this simple method:

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;
}

And then when user wants to see the stored image, I open it using gallery intent:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file://" + m_ImageFilename);
intent.setDataAndType(uri, "image/*");
startActivity(intent);

However, gallery shows only the single image file pointed by m_ImageFilename despite there are other images stored in the same folder.

Thus actual behaviour of gallery intent is this:

enter image description here

While expected behaviour is this:

enter image description here

As an important note, I must mention that after restarting phone, gallery intent shows all images in folder as expected. Also, the behaviour is same on all versions from Jelly Bean to Marshmallow.

So each time after saving image, user has to restart phone in order to see all images in folder through gallery intent.

Please can someone tell what am I missing here and how can this be fixed?

1

There are 1 best solutions below

1
On

You need to add saved image to gallery ... This will help you.