本文介绍了从MediaStore空指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想不通为什么这个指针为空仅这一个特定的设备。但在所有其他Android设备的工作原理。上有SD卡数语音文件,以及股票媒体播放器可以找到并好吗播放这些歌曲。

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

无论是闲逛书播放器(我猜他们通过文件夹只是环路,做自己的ID3解析)和股票的Andr​​oid音乐播放器找到音乐,但我不能让从​​mediastore任何东西。没有.nomedia文件是present,我试图插入新的MP3文件到一个新的文件夹。

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.

推荐答案

我遇到类似的,并发现了几个答案,其中没有一个尚未被证明令人满意。

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

响应于系统中的介质扫描仪运行烧制广播意图ACTION_MEDIA_MOUNTED,它在引导过程中发生的情况。所以,第一件事是检查重启。

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.

据我所知,扫描仪也将也将后运行设置>管理应用程序>媒体存储>清除数据 - 并重新填充从存储的mediastore。我想这和它的工作没有,我会实现。我不能保证,当然安全,也不会非开发设备上做到这一点。

From what I understand, the scanner will also will also run afterSettings > 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.

您也可以手动

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

和提出了某种形式的通知,同时观察意图ACTION_MEDIA_SCANNER_FINISHED的广播。

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

如果您正在导入媒体自己,请查看 MediaScannerConnection 踢扫描仪。

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

哦,如果你打算去,如谷歌的Nexus设备,你需要处理INTERNAL_CONTENT_URI。

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

这篇关于从MediaStore空指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 06:55