Trying to rescan for audio files

289 views Asked by At

Ok, I have been looking at this issue for 8 hours straight now. I am testing a mediaplayer application from a tutorial. It works properly but any new mp3 files added are not available within my RecyclerView list. I have searched and found that I must refresh by rescanning the storage for the new files to be available from the database. The problem is, I cannot find any working methods that work for me. I must have browsed into like 10 threads with the same issue. Some people are complaining about the issue with kitkat 4.4 and some complain about the Marshmallow devices.

I have tried the broadcasting solution. It does not work on Kitkat because of the permission being restricted to the system on Kitkat. Also, the same solution resulted in me losing all my current records on my list on my Lollipop device. I cannot seem to refresh it at all. I am talking about this solution:

getApplicationContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));

or

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()));

I ended up trying two more solutions without luck. I have tried this one:

MediaScannerConnection.scanFile(this, new String[] { Environment.getExternalStorageDirectory().toString() }, null, new MediaScannerConnection.OnScanCompletedListener() {
        public void onScanCompleted(String path, Uri uri)
        {

        }
});

I have tried a couple of other solutions without luck. Is there any working solution to rescan the file storage for all the mp3 files available on >=api16.

1

There are 1 answers

0
Jack On BEST ANSWER

Well, I guess the only thing one can do is not rely on the MediaStore at all. One would have to access the storage directly. I can see no other solution.