gpt4 book ai didi

android - MediaStore.Audio.Artists 中没有 "number_of_albums column"

转载 作者:行者123 更新时间:2023-11-30 03:03:17 24 4
gpt4 key购买 nike

我想从 MediaStore 中检索数据,尤其是每个艺术家的专辑数量,但 SQLite 抛出异常

no such column: number_of_albums (code 1): while compiling: SELECT artist_key, artist, number_of_albums FROM audio WHERE (is_music != 0)

谁能解释一下我做错了什么?

我的代码:

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

关于android - MediaStore.Audio.Artists 中没有 "number_of_albums column",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22244673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com