Android MediaScannerConnection or sendBroadcast for scanning ".m3u"

932 views Asked by At

I am writing an app that creates ".m3u" files. At the end of the app run I try to scan for new media (m3u) files. At first I was using sendBroadcast function:

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

After updating my Android from 4.3 to 4.4 Kitkat this code crashes my application.

not allowed to send broadcast android.intent.action.MEDIA_MOUNTED

I found in the internet next solution:

    MediaScannerConnection.scanFile(this,
            new String[] { file.toString() }, null,
            new MediaScannerConnection.OnScanCompletedListener() {
                public void onScanCompleted(String path, Uri uri) {
                    Log.i("ExternalStorage", "Scanned " + path + ":");
                    Log.i("ExternalStorage", "-> uri=" + uri);
                }
            });

The code above is not crashes my app but doesn't scan an ".m3u" file. I create playlist but applications(media players) don't see it. When I was using sendBroadcast - everything was fine. What's wrong with MediaScannerConnection code? I see log that file is scanned, but uri is null. MediaScannerConnection doesn't scan for ".m3u" files? What should I do?

Thank you for help.

0

There are 0 answers