问题描述
我正在使用以下代码将音乐添加到播放列表,并且它在 android sdk
上正常工作但是当我将目标sdk更新为android sdk 30时(还启用了android:requestLegacyExternalStorage="true"
)
它像这样崩溃
java.lang.IllegalArgumentException: Invalid column count(*)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:170)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:423)
at android.content.ContentResolver.query(ContentResolver.java:944)
at android.content.ContentResolver.query(ContentResolver.java:880)
at android.content.ContentResolver.query(ContentResolver.java:836)
at cn.jzvd.demo.utils.MusicUtils.addToPlaylist(MusicUtils.java:248)
at cn.jzvd.demo.musciplayermodule.PlayList.PlaylistSubFragment$4.onClick(PlaylistSubFragment.java:339)
at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
public static void addToPlaylist(Context context,long[] ids,long playlistid) {
if (ids == null) {
Log.e("MusicBase","ListSelection null");
} else {
Cursor cur;
int size = ids.length;
ContentResolver resolver = context.getContentResolver();
String[] cols = new String[]{"count(*)"};
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external",playlistid);
cur = resolver.query(uri,cols,null,null); //<- crashing here
if (cur != null) {
cur.movetoFirst();
int base = cur.getInt(0);
cur.close();
int numinserted = 0;
try {
for (int i = 0; i < size; i += 1000) {
makeInsertItems(ids,i,1000,base);
numinserted += resolver.bulkInsert(uri,sContentValuesCache);
}
} catch (Exception e) {
e.printstacktrace();
}
}
if (cur != null) cur.close();
}
}
我真的陷入了困境,如果有人只是编辑相同的功能以使其与android sdk 29/30一起使用,我会更喜欢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)