6

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?

Community
  • 1
  • 1
Justin
  • 3,322
  • 2
  • 22
  • 37
  • Have you tried something like [this](http://stackoverflow.com/questions/6108243/contentresolver-in-android-2-2-issue)? I'd think the ACTION_MEDIA_SCANNER_SCAN_FILE might help, and if not, you could get a ContentProvider for MediaStore.Audio and call the new requestSync method on it. Just my thoughts, I haven't tried either of these. – Tom Feb 28 '14 at 03:51
  • Thanks for the comment. No of those solutions work. The issue is getting Android to populate the metadata like it does on the SD card. Updated the question a little bit to make that clearer. – Justin Mar 05 '14 at 17:09
  • Since "/SDCard/Android/data/App Package Name" is your apps private folder which other non-superuser-apps apps are not allowed to read from other Android music players cannot play your mp3 even if they are in the media-db. In android prior to 4.4 it was possible to allow other apps to read from some private folder. but this does not work in android-4.4 and later any more. – k3b Sep 23 '15 at 10:50
  • @Justin did you find any solution yet ? if not, any other solution to get this sorted ? – Ahmed Jan 13 '16 at 16:59

1 Answers1

6

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

Justin
  • 3,322
  • 2
  • 22
  • 37