Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Add Media To MediaStore on Android 4.4 KitKat SD Card With Metadata

Background: In Android 4.4, Google decided that apps should not have write access to SD cards.

However, apps can write to /SDCard/Android/data/App Package Name.

So this is what I've done. I have written an MP3 file to /Android/data/. I then want this MP3 file to show up in Android music players.

I've tried the following...

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

and....

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

and...

ContentResolver.requestSync(CreateSyncAccount(context), MediaStore.AUTHORITY, null);

both of these will add the file to the MediaStore as a file with a URI like content://media/external/file/xxxxx

However, the file is not added as audio. I can update the MediaStore to declare the file as audio, but the file metadata isn't imported.

Other than write my own tag reader, how can I get the media scanner to scan the file and insert metadata like it does on the internal memory and pre-KitKat SD cards?

like image 651
Justin Avatar asked Feb 28 '14 01:02

Justin


1 Answers

I've given up looking for a solution. I do not think there is one, so I've filed an issue report.

like image 59
Justin Avatar answered Oct 17 '22 13:10

Justin