如何使用元数据将媒体添加到 Android 4.4 KitKat SD 卡上的 MediaStore [英] How To Add Media To MediaStore on Android 4.4 KitKat SD Card With Metadata

本文介绍了如何使用元数据将媒体添加到 Android 4.4 KitKat SD 卡上的 MediaStore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:在 Android 4.4 中,Google 决定应用应该不拥有对 SD 卡的写权限.

但是,应用可以写入/SDCard/Android/data/App Package Name.

这就是我所做的.我已将 MP3 文件写入/Android/data/.然后我希望这个 MP3 文件显示在 Android 音乐播放器中.

我已经尝试了以下...

<前>sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ 文件路径)));

和....

<前>MediaScannerConnection.scanFile(这个,new String[] { file.toString() }, new String[] {"audio/*"},新 MediaScannerConnection.OnScanCompletedListener() {公共无效 onScanCompleted(字符串路径,Uri uri){Log.i("ExternalStorage", "已扫描" + 路径 + ":");Log.i("ExternalStorage", "-> uri=" + uri);}});

还有……

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

这两者都会将文件作为具有 URI 的文件添加到 MediaStore,例如 content://media/external/file/xxxxx

但是,该文件并未添加为音频.我可以更新 MediaStore 以将文件声明为音频,但不会导入文件元数据.

除了编写我自己的标签阅读器,我如何才能让媒体扫描仪扫描文件并插入元数据,就像它在内部存储器和 KitKat 之前的 SD 卡上所做的那样?

解决方案

我已经放弃寻找解决方案了.我认为没有,所以我提交了问题报告.

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.

这篇关于如何使用元数据将媒体添加到 Android 4.4 KitKat SD 卡上的 MediaStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆