On Android: How can I rescan an entire folder to watch for changes in .nomedia

倾然丶 夕夏残阳落幕 提交于 2019-11-28 08:32:08

问题


So my app downloads images at the users' request from an online source. Through a button in the activity, the user can choose to hide or show the images in the gallery. This is easy enough, I just add or remove a .nomedia file as needed. However, I want to rescan media every time so that the change is instant, and requires no further user interaction.

After each image is downloaded, I am using the method at http://www.mail-archive.com/android-developers@googlegroups.com/msg24164.html to scan the specific image into the library. That works great for one image, but when the .nomedia file is added, I really need to be able to scan a whole directory.

I have considered calling the MediaScannerNotifier on each image in the directory, but that just seems clumsy and lazy.

Advice?


回答1:


Finally found it at http://groups.google.com/group/android-developers/browse_thread/thread/c1a385226f3df482.

It is a one-liner:

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



回答2:


am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///mnt/sdcard

This command can be used to update the SD Card without rebooting the device




回答3:


One can also invoke from the shell:

am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///mnt/sdcard


来源:https://stackoverflow.com/questions/3410807/on-android-how-can-i-rescan-an-entire-folder-to-watch-for-changes-in-nomedia

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