如何在 Nexus 7 上触发 MediaScan? [英] How to trigger MediaScan on Nexus 7?

查看:26
本文介绍了如何在 Nexus 7 上触发 MediaScan?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我想确保 MediaStore 具有最新信息而无需重新启动我想使用我在 SO 上找到的流行方式触发 MediaScanner

Because I want to make sure the MediaStore has the latest information without having to reboot I'd like to trigger the MediaScanner using the popular way I found on SO

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

这在带 ICS 的三星 S2 上运行良好,但在带 JellyBean 的 Nexus 7 上不起作用.Logcat 在我的 Nexus 7 上显示了这一点:

This works fine on my Samsung S2 w/ICS but not on my Nexus 7 w/JellyBean. Logcat shows this on my Nexus 7:

WARN/ActivityManager(480): Permission denied: checkComponentPermission() owningUid=10014
WARN/BroadcastQueue(480): Permission Denial: broadcasting Intent { act=android.intent.action.MEDIA_MOUNTED dat=file:///storage/emulated/0 flg=0x10 } from com.example.foo.bar (pid=17488, uid=10046) is not exported from uid 10014 due to receiver com.android.providers.downloads/.DownloadReceiver
INFO/ActivityManager(480): Start proc com.google.android.music:main for broadcast com.google.android.music/.store.MediaStoreImportService$Receiver: pid=17858 uid=10038 gids={50038, 3003, 1015, 1028}
INFO/MusicStore(17858): Database version: 50
INFO/MediaStoreImporter(17858): Update: incremental Added music: 0 Updated music: 0 Deleted music: 0 Created playlists: 0 Updated playlists: 0 Deleted playlists: 0 Inserted playlist items: 0 Deleted playlist items: 0 Removed orphaned playlist items: 0

最后一行在理论上听起来很鼓舞人心,但即使在将新文件推送到 SD 卡(通过 adb push)之后,这些值也始终为 0.在我的旧设备 (S2) 上,它确实重新安装了 SD 卡.

The last line sounds encouraging in theory, but the values are always 0 even after new files had been pushed to the SD card (via adb push). On my older device (S2) it does remount the SD card.

我已经向我的 AndroidManifest.xml 添加了以下权限,但它的行为与没有这些权限的行为相同:

I've added the following permissions to my AndroidManifest.xml but it behaves the same as without those permissions:

<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

任何想法/替代方案?

编辑 1:

请注意,我不知道新文件、已修改文件或已删除文件的任何文件路径.我只想确保 MediaStore 是最新的.

Note that I don't know any file paths of new or modified or deleted files. I just want to make sure the MediaStore is up-to-date.

推荐答案

使用我在 SO 上找到的流行方式

using the popular way I found on SO

恕我直言,伪造ACTION_MEDIA_MOUNTED广播从来都不是一个合适的解决方案.

Faking ACTION_MEDIA_MOUNTED broadcasts has never been an appropriate solution IMHO.

任何想法/替代方案?

使用MediaScannerConnection,如通过 它的 scanFile() 静态方法.

这篇关于如何在 Nexus 7 上触发 MediaScan?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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