MediaStore managedQuery not returning the newest files
<p>I am querying the MediaStore to get the videos based on a duration of (MAX 15 seconds). </p>

<p>The problem I am facing is when I record a video using the gallery. Then, if I go to my app, this video does not show up in this cursor. However, if I go to the gallery and open the video, it is returned the next time I query.</p>

<p>Here is my query:</p>

<pre><code>private Cursor getVideos() {
        _.log("getVideos");
        String[] proj = { MediaStore.Video.Media._ID,
                MediaStore.Video.Media.DATA,
                MediaStore.Video.Media.DISPLAY_NAME,
                MediaStore.Video.Media.SIZE, MediaStore.Video.Media.DATE_TAKEN,
                MediaStore.Video.Media.DURATION };

        return managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj,
                MediaStore.Video.Media.DURATION + "&lt;=?" + " AND "
                        + MediaStore.Video.Media.DURATION + "&gt;=?" + " AND "
                        + MediaStore.Video.Media.SIZE + "&gt;=?", new String[] {
                        "15000", "1000", "1000" }, null);
    }
</code></pre>

<hr>

<p><strong>Possible solution</strong> would be to force a refresh before querying. I tried this using the following code which utilizes a MediaScannerConnection:</p>

<pre><code>_.log("new MediaScannerConnection");
msc = new MediaScannerConnection(mContext, new MediaScannerConnectionClient() {

    public void onScanCompleted(String path, Uri uri) {
        _.log("onScanCompleted:"+path);
        msc.disconnect();
        synchronized (lock) {
            lock.notifyAll();
        }
    }

    public void onMediaScannerConnected() {
        _.log("onMediaScannerConnected:" + MediaStore.Video.Media.EXTERNAL_CONTENT_URI.toString());
        msc.scanFile(MediaStore.Video.Media.EXTERNAL_CONTENT_URI.getPath(),
                null);
    }
});
_.log("connect");
msc.connect();
synchronized (lock) {
    try {
        _.log("waiting");
        lock.wait();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    _.log("done waiting");
}
</code></pre>

<p>However this did not solve the problem. On some phones, I am getting onMediaScannerConnected called multiple times and never onScanCompleted</p>
