1
我正在嘗試編寫應用程序,其中列出了來自SD卡的所有mp3文件。託管查詢問題
String[] columns = new String[] {
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.TITLE_KEY,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ARTIST_ID,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.TRACK
};
String uristr_t = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.getPath();
Cursor musicCursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
columns, null, null, null);
if(musicCursor != null){
mSongs = new ArrayList<SongInfo>(musicCursor.getCount());
boolean isMediaFilesExist = musicCursor.moveToFirst();
...
有SD卡,但musicCursor.GetCount()上的一些的MP3文件,返回0。我想,路徑不正確。 EXTERNAL_CONTENT_URI是content://media/external/audio/media
其路徑是:
/external/audio/media
但我的SD卡的路徑是:
/mnt/sdcard
我已經試過手動設置烏里:
String uriStr = "content://" + Environment.getExternalStorageDirectory().getPath();
Uri sdCardUri = Uri.parse(uriStr);
Cursor musicCursor = managedQuery(sdCardUri, columns, null, null, null);
在這種情況下,烏里是content:///mnt/sdcard
,但在managedQuery之後musicCursor爲null。也許uriStr格式不正確,Uri初始化錯誤? 謝謝!
謝謝,Nic!重新安裝幫助!現在一切正常。 – Artem 2011-04-13 04:44:52