Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ContentResolver.query always returns same data
    text
    copied!<p>I have videoplayer app with filebrowser listing all videos on SD card</p> <p>Code inspired by <a href="https://stackoverflow.com/questions/5590628/i-want-get-audio-files-in-sd-card">i want get audio files in sd card</a></p> <p>Using ContentResolver, works as expected, but it does not update if the files on card change. I do not mean automatically, but after view/app restart. Not even reinstalling the application helped, still shows the same files. The deleted video file is not visible via PC nor it is possible to play it (This video cannot be played (translation)).</p> <p>I dumped the data and the problem is not in view caching or elsewhere. I do not implement any caching of my own and failed to find anything on the matter. Thank you</p> <p>Code:</p> <pre><code> // acquisition String[] projection = { MediaStore.Video.Media._ID, MediaStore.Video.Media.DISPLAY_NAME, MediaStore.Video.Media.DURATION, MediaStore.Video.Media.DATA }; ContentResolver resolver = getActivity().getContentResolver(); Cursor videoCursor = resolver.query( MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, null, null, null ); // extraction while(cursor.moveToNext()) { cursorIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); filepath = cursor.getString(cursorIndex); cursorIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME); filename = cursor.getString(cursorIndex); cursorIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION); duration = cursor.getString(cursorIndex); result[ index++ ] = new VideoFileMetadata(filename, duration, filepath); } </code></pre> <p>Edit 1 [14-03-2013]: </p> <p>I tried adding <code>number + " = " + number</code> to ORDER or WHERE clause to act as a potential query caching buster, but it had no effect (although it's possible it was removed by an optimizer as a useless clause). This time I had reinstalled the application from a different machine using different certificate, but the query result remained the same, listing currently non-existing files.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload