Media file information not updatable to ContentResolver.query

I am writing an Android app that allows me to update my media. I have an AsyncTask that (among other things) scans the device for media files.

Below is the code used to get all media files and create a FileInfo list (my class containing the main metadata of the files).

The problem is that the data received from Cr().query

is always the same and does not bring the latest updates.

I looked at this similar issue , but you can see that my code does the solution recommended there, but I still get old data, not updated.

Spent me trying to figure out that this is the problem, but now I can clearly see it in the output of the log statement Log.d("scanLocalFiles", "" + fileInfos.size() + "|" + data + ":" + size );

that the file I know that was modified still appears with its original size. (I know it has been changed because I see it updated in ES-FileExplorer ...)

Any suggestion on what might be going on?


Code below:

private List<FileInfo> scanLocalFiles(Uri... uris)
    List<FileInfo> fileInfos = new ArrayList<FileInfo>();
    String[] projection = new String[]{
    for (int u=0; u < uris.length; u++)
        Uri uri = uris[u];

        //Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

        Cursor cur = Cr().query(uri,
                projection, // Which columns to return
                "",         // Which rows to return (all rows)
                null,       // Selection arguments (none)
                ""          // Ordering

        if(cur!=null && cur.moveToFirst())
                int idColumn = cur.getColumnIndex(projection[0]);
                int dataColumn = cur.getColumnIndex(projection[1]);
                int sizeColumn = cur.getColumnIndex(projection[2]);
                int mimeColumn = cur.getColumnIndex(projection[3]);
                    Uri id = Uri.withAppendedPath(uri, cur.getString(idColumn));
                    String data = cur.getString(dataColumn);
                    long size = cur.getLong(sizeColumn);
                    String mime = cur.getString(mimeColumn);
                    Log.d("scanLocalFiles", "" + fileInfos.size() + "|" + data + ":" + size );
                    fileInfos.add(new FileInfo(id, data, size, mime));

                } while (cur.moveToNext());
            catch (Exception ex)

    return fileInfos;



source to share

All Articles