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

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

问题描述

由于我要确保MediaStore具有无需重启,我想用我发现在流行的方式来触发MediaScanner的最新信息,以便

  context.sendBroadcast(新意图(Intent.ACTION_MEDIA_MOUNTED,
                                 Uri.parse(文件://+ Environment.getExternalStorageDirectory())));
 

这正常工作对我的三星S2瓦特/ ICS却没有关于我的Nexus 7W /软糖。 LogCat中显示了这对我的Nexus 7:

  WARN / ActivityManager(480):权限被拒绝:checkComponentPermission()owningUid = 10014
WARN / BroadcastQueue(480):权限拒绝:广播意图{行为= android.intent.action.MEDIA_MOUNTED DAT =文件:///存储/模拟/ 0 FLG = 0×10}从com.example.foo.bar(PID = 17488 ,UID = 10046),不是从UID 10014远销由于接收器com.android.providers.downloads / .DownloadReceiver
信息/ ActivityManager(480):开始PROC com.google.android.music:主要用于广播com.google.android.music / .store.MediaStoreImportService $接收器:PID = 17858的uid = 10038导报= {50038,3003,1015, 1028}
信息/ MusicStore(17858):数据库版本:50
信息/ MediaStoreImporter(17858):更新:增量添加的音乐:0更新音乐:0删除音乐:0创建的播放列表:0更新播放列表:0删除播放列表:0插入播放列表中的项目:删除播放列表中的项目:删除孤立的播放列表中的项目:0
 

最后一行的声音,鼓励在理论上,但值始终为0,即使新的文件已被推迟到SD卡(通过ADB推)。在我的旧设备(S2),它重新安装SD卡。

我添加以下权限到我的Andr​​oidManifest.xml中,但它的行为与没有这些权限:

 <使用-权限的Andr​​oid:名称=android.permission.MOUNT_UNMOUNT_FILESYSTEMS/>
<使用-权限的Andr​​oid:名称=android.permission.READ_EXTERNAL_STORAG​​E/>
<使用-权限的Andr​​oid:名称=android.permission.WRITE_EXTERNAL_STORAG​​E/>
 

任何想法/替代品?


修改1:

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

解决方案
  

使用我发现在流行的方式,使

假装 ACTION_MEDIA_MOUNTED 节目从来不是一个合适的解决方案恕我直言。

  

任何想法/替代品?

使用 MediaScannerConnection ,这样的作为通过<一个href="http://developer.android.com/reference/android/media/MediaScannerConnection.html#scanFile%28android.content.Context,%20java.lang.String%5B%5D,%20java.lang.String%5B%5D,%20android.media.MediaScannerConnection.OnScanCompletedListener%29">its SCANFILE()静态方法。

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())));

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

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.

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"/>

Any ideas/alternatives?


Edit 1:

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.

解决方案

using the popular way I found on SO

Faking ACTION_MEDIA_MOUNTED broadcasts has never been an appropriate solution IMHO.

Any ideas/alternatives?

Use MediaScannerConnection, such as via its scanFile() static method.

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

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