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

我只是一个虾纸丫 提交于 2019-12-29 04:24:32

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!