Empty cursor from the MediaStore

我们两清 提交于 2019-11-28 10:31:33

I've encountered similar, and discovered several answers of which none has yet proven satisfactory.

The media scanner runs in response to the system fired broadcast Intent ACTION_MEDIA_MOUNTED, which happens during boot. So 1st thing to check is reboot.

From what I understand, the scanner will also will also run after Settings > Manage Applications > Media Storage > Clear Data - and re-populate the mediastore from the storage. I tried that and it worked without I'll effect.. I can't guarantee safety of course and wouldn't do this on a non-dev device.

You can also manually

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

and put up some kind of notice while watching for the broadcast of intent ACTION_MEDIA_SCANNER_FINISHED.

If you are importing media yourself, check out MediaScannerConnection to kick the scanner.

Oh, and if you plan to go to devices such as Google's Nexus, you'll need to deal with INTERNAL_CONTENT_URI.

I have the same problem on a HTC Incredible and sadly DJC's answer didn't work for me. Both the EXTERNAL_CONTENT_URI and INTERNAL_CONTENT_URI didn't give me any images. After some digging I found that by using the following content URI, it did seem to work on the HTC Incredible.

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