我有Service
定期检查缺少的专辑封面和必要时的更新。它在 pre-Lollipop 设备上完美运行,但在Lollipop上没有。
以下代码段来自服务。
private static final Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
ContentValues values = new ContentValues();
values.put("album_id", albumId);
values.put("_data", file.getAbsolutePath());
Uri newuri = this.getContentResolver().insert(sArtworkUri, values);
if (newuri == null) {
// Failed to insert in to the database. The most likely
// cause of this is that the item already existed in the
// database, and the most likely cause of that is that
// the album was scanned before, but the user deleted the
// album art from the sd card.
// So we try to update the row
Uri uri = ContentUris.withAppendedId(sArtworkUri, Long.parseLong(albumId));
int updatednum = this.getContentResolver().update(uri, values, null, null); //Getting error at this line on Lollipop
if(updatednum < 1) success = false;
}
我在 Lollipop 设备的指示行上收到以下异常
android.database.sqlite.SQLiteException: no such column: _id (code 1): , while compiling: SELECT _id FROM album_art WHERE album_id=4
我试图找出MediaStore
是否有任何变化,但我已经空了。有人知道为什么片段中显示的行在Lollipop上失败了吗?
提前致谢!
答案 0 :(得分:1)
由于问题在于update()
方法,我决定通过避免完全使用update()
来解决此问题。以下delete()
和insert()
的组合消除了对update()的需求。
this.getContentResolver().delete(ContentUris.withAppendedId(sArtworkUri, Long.parseLong(albumId)), null, null);
newuri = this.getContentResolver().insert(sArtworkUri, values);