我最后做的是
ContentProviderOperation
和
getContentResolver().applyBatch
applyBatch
你必须把它包装成一个try..catch,它报告的Android Studio错误并不明显。以下是最终代码:
Cursor songs = createPlaylistCursor(sort);
if (songs.moveToFirst()) {
int i = 0;
Uri playListUri = getPlaylistUri();
ArrayList<ContentProviderOperation> cs = new ArrayList<ContentProviderOperation>();
do {
cs.add(ContentProviderOperation.newUpdate(playListUri)
.withSelection("folder_file_id=" + songs.getInt(songs.getColumnIndexOrThrow("folder_files._id")), null)
.withValue("sort", i++)
.build());
} while (songs.moveToNext());
try {
getContentResolver().applyBatch("com.maxmpz.audioplayer.data", cs);
}
catch (Exception e) {
}
}