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?

Thank.

Code below:

private List<FileInfo> scanLocalFiles(Uri... uris)
{
    List<FileInfo> fileInfos = new ArrayList<FileInfo>();
    String[] projection = new String[]{
            MediaStore.MediaColumns._ID,
            MediaStore.MediaColumns.DATA,
            MediaStore.MediaColumns.SIZE,
            MediaStore.MediaColumns.MIME_TYPE
    };
    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())
        {
            try
            {
                int idColumn = cur.getColumnIndex(projection[0]);
                int dataColumn = cur.getColumnIndex(projection[1]);
                int sizeColumn = cur.getColumnIndex(projection[2]);
                int mimeColumn = cur.getColumnIndex(projection[3]);
                do
                {
                    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)
            {
                ex.printStackTrace();
            }
            finally
            {

                cur.close();
            }
        }
    }
    return fileInfos;
}

      

+3
android android-contentresolver android-cursor


source to share


No one has answered this question yet

See similar questions:

0
Android ContentResolver.query always returns the same data

or similar:

1169
Is there a way to get the source code from the APK file?
964
Download file from Android and show progress in ProgressDialog
862
What are the "tools: context" in android layout files?
572
ViewPager PagerAdapter does not update View
46
Unable to display HTML string
6
How to add media to MediaStore on Android 4.4 KitKat SDK card with metadata
4
Loadmanager onLoadFinished is not called
1
How to get list of mp3 files from SdCard using ContentResolver.Query on Android?
0
Image tracking after adding to media scanner (when user selects it from gallery)
-4
What is the term used to update SQLiteDatabase?



All Articles
Loading...
X
Show
Funny
Dev
Pics