0

How to do a manual refresh of the mediastore content provider in android.

I have added new files to the storage and the new files which are not getting in the mediastore , After doing a restart am getting the newly added file.

This soloution is pretty fine

How can I refresh MediaStore on Android?

but it does not give any solution for newly added files

Community
  • 1
  • 1
Ajay Venugopal
  • 1,544
  • 1
  • 17
  • 30

2 Answers2

-1

For the requirement that you are talking about you do not need to restart the app. Android is proving one method or mechanism to refresh the mediastore. Add the following line of code just below when you add the files.

MediaScannerConnection.scanFile(context, new String[]{f.getPath()}, null, null);

in the above f is the object of file.

Lalit Dhameliya
  • 348
  • 3
  • 8
-1
MediaScannerConnection.scanFile(mContext,new String[] { videoUrl }, null, new MediaScannerConnection.OnScanCompletedListener() 
        {
            public void onScanCompleted(String path, Uri uri) 
            {
                Log.i("ExternalStorage", "Scanned " + path + ":");
                Log.i("ExternalStorage", "-> uri=" + uri);
            }
        });