没有“相册数列";在MediaStore.Audio.Artists中 [英] No "number_of_albums column" in MediaStore.Audio.Artists
问题描述
我想从MediaStore检索数据,尤其是每位艺术家的专辑数量,但是SQLite抛出异常
I want to retrieve data from MediaStore especially the number of albums per artist but SQLite throws me an exception
没有这样的列:number_of_albums(代码1):编译时:从音频WHERE中选择artist_key,artist,number_of_albums(is_music!= 0)
no such column: number_of_albums (code 1): while compiling: SELECT artist_key, artist, number_of_albums FROM audio WHERE (is_music != 0)
有人可以向我解释我在做什么错吗?
Can someone explain me what I am doing wrong?
我的代码:
private List<Artist> getArtistList() {
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
String[] projection = {
MediaStore.Audio.Artists.ARTIST_KEY,
MediaStore.Audio.Artists.ARTIST,
MediaStore.Audio.Artists.NUMBER_OF_ALBUMS
};
Cursor cursor = this.getActivity().getApplicationContext().getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
projection,
selection,
null,
null);
List<Artist> artists = new ArrayList<Artist>();
Artist tmp = null;
if (cursor.moveToFirst()) {
do {
tmp = new Artist(cursor.getString(0),
cursor.getString(1),
Integer.parseInt(cursor.getString(2)));
artists.add(tmp);
} while (cursor.moveToNext());
}
return artists;
}
谢谢!
推荐答案
您正在为该列查询错误的内容URI.使用 MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI
而不是 MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
.
You're querying the wrong content URI for that column. Use MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI
instead of MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
.
这篇关于没有“相册数列";在MediaStore.Audio.Artists中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!