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?
I've given up looking for a solution. I do not think there is one, so I've filed an issue report.
来源:https://stackoverflow.com/questions/22084436/how-to-add-media-to-mediastore-on-android-4-4-kitkat-sd-card-with-metadata