Hi All
i am creating a music player app, To get list of songs i am using android MediaStore dataprovider as below
ContentResolver contentResolver = getBaseContext().getContentResolver();
Uri uri = MediaStore.Audio.Media.getContentUri("external");
String[] proj = null;
String selectionMimeType = MediaStore.Files.FileColumns.MIME_TYPE+"=?";
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension("mp3");
String[] selectoinArgsMp3 = new String[]{mimeType};
Cursor allMediaFiles = contentResolver.query(uri, proj, selectionMimeType,selectoinArgsMp3, null);
but i am facing challenge to update MediaStore when ever a file is added, after goggling i found the below solutions
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory() )));
which is not working because google is preventing it to be invoked by other apps other than system apps as of my understanding.
- Another solution is by using
FileObserver
but this is not recursive. if we know the file name we can update MediaStore by using the below code but we don't have any control to get the file name because user can download a song or move a song.
MediaScannerConnection.scanFile(file.getAbsolutePath(),"mimetype");
Last solution is to scan manually ,but scanning 3GB(by considering on an average) manually is time consuming process
So can any one please share any ideas or resource
Thanks