Question

I can't figure out why this cursor is empty in just this one particular device. but works on all other android devices. There are several audiofiles on the sdcard, and the stock mediaplayer can find and play these songs alright.

Cursor c = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { "distinct " + MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ALBUM_KEY, MediaStore.Audio.Media.ALBUM_ID}, 
                null,
                null, 
                MediaStore.Audio.Media.ARTIST);

Both the ambling book player (I'm guessing they just loop through the folders and do their own id3 parsing) and the stock android music player find the music but I can't get anything from the mediastore. No ".nomedia" files are present, I have tried inserting new mp3 files to a new folder.

Was it helpful?

Solution

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.

OTHER TIPS

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");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top