因为我想确保MediaStore有最新的信息,而不必重新启动我想用流行的方式,我发现SO触发MediaScanner
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
这工作正常,在我的三星S2 W / ICS却没有关于我的Nexus 7 W /豆形软糖。 logcat中显示了这个在我的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
最后一行在理论上听起来鼓舞人心的,但值始终为0,即使之后的新文件已经被推到SD卡(通过ADB推)。 在我的旧的设备(S2),它重新安装SD卡。
我已经添加了以下权限到我的AndroidManifest.xml中,但它的行为与没有这些权限:
<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是最新的更新。