我正在尝试更新MediaStore.Audio.Albums
中ALBUM_ID
的某些行,但我收到此错误
java.lang.UnsupportedOperationException:未知或不支持的网址:content:// media / internal / audio / albums
以下是代码:
ctx.getContentResolver().update(
MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
values,
MediaStore.Audio.Albums.ALBUM_ID + "=" + 16,
null);
答案 0 :(得分:0)
.update()
总是会抛出此错误
java.lang.UnsupportedOperationException:未知或不支持的网址:content:// media / internal / audio / albums
要更新,请先删除行,然后重新插入。
例如
首先,删除要更新的行
Uri albumArtUri = Uri.parse("content://media/external/audio/albumart");
ctx.getContentResolver().delete(ContentUris.withAppendedId(albumArtUri, 16), null, null);
ctx.getContentResolver().delete(ContentUris.withAppendedId(albumArtUri, 25), null, null);
ctx.getContentResolver().delete(ContentUris.withAppendedId(albumArtUri, 24), null, null);
ctx.getContentResolver().delete(ContentUris.withAppendedId(albumArtUri, 30), null, null);
ctx.getContentResolver().delete(ContentUris.withAppendedId(albumArtUri, 14), null, null);
ctx.getContentResolver().delete(ContentUris.withAppendedId(albumArtUri, 31), null, null);
ctx.getContentResolver().delete(ContentUris.withAppendedId(albumArtUri, 28), null, null);
ctx.getContentResolver().delete(ContentUris.withAppendedId(albumArtUri, 23), null, null);
ctx.getContentResolver().delete(ContentUris.withAppendedId(albumArtUri, 17), null, null);
ctx.getContentResolver().delete(ContentUris.withAppendedId(albumArtUri, 16), null, null);
ctx.getContentResolver().delete(ContentUris.withAppendedId(albumArtUri, 13), null, null);
其次,重新插入行
ContentValues insertionValues = new ContentValues();
insertionValues.put("_data", "Dummy path");
insertionValues.put("album_id", 16);
ctx.getContentResolver().insert(albumArtUri, insertionValues);
insertionValues.put("_data", "Dummy path");
insertionValues.put("album_id", 25);
ctx.getContentResolver().insert(albumArtUri, insertionValues);
insertionValues.put("_data", "Dummy path");
insertionValues.put("album_id", 24);
ctx.getContentResolver().insert(albumArtUri, insertionValues);
insertionValues.put("_data", "Dummy path");
insertionValues.put("album_id", 30);
ctx.getContentResolver().insert(albumArtUri, insertionValues);
insertionValues.put("_data", "Dummy path");
insertionValues.put("album_id", 14);
ctx.getContentResolver().insert(albumArtUri, insertionValues);
insertionValues.put("_data", "Dummy path");
insertionValues.put("album_id", 31);
ctx.getContentResolver().insert(albumArtUri, insertionValues);
insertionValues.put("_data", "Dummy path");
insertionValues.put("album_id", 28);
ctx.getContentResolver().insert(albumArtUri, insertionValues);
insertionValues.put("_data", "Dummy path");
insertionValues.put("album_id", 23);
ctx.getContentResolver().insert(albumArtUri, insertionValues);
insertionValues.put("_data", "Dummy path");
insertionValues.put("album_id", 17);
ctx.getContentResolver().insert(albumArtUri, insertionValues);
insertionValues.put("album_id", 16);
insertionValues.put("_data", "Dummy path");
ctx.getContentResolver().insert(albumArtUri, insertionValues);
insertionValues.put("album_id", 13);
insertionValues.put("_data", "Dummy path");
ctx.getContentResolver().insert(albumArtUri, insertionValues);
如果您打印结果
dumpCursorByAlbumId("16");
dumpCursorByAlbumId("25");
dumpCursorByAlbumId("24");
dumpCursorByAlbumId("30");
dumpCursorByAlbumId("14");
dumpCursorByAlbumId("31");
dumpCursorByAlbumId("28");
dumpCursorByAlbumId("23");
dumpCursorByAlbumId("17");
dumpCursorByAlbumId("16");
dumpCursorByAlbumId("13");
你会看到你所做的就是更新单个细胞!
0 {
_id=16
album_art=Dummy path
artist=Keith Jarrett & Charlie Haden
artist=Keith Jarrett & Charlie Haden
numsongs=9
album_key= ? ) M O / ) C - 1 1611567005
}
<<<<<
>>>>> Dumping cursor android.content.ContentResolver$CursorWrapperInner@26cf2dde
0 {
_id=25
album_art=Dummy path
artist=John Coltrane
artist=John Coltrane
numsongs=4
album_key= ? E S 1 M Q G K 1 A 1 S 1 K S 1 K 1 9 M M Q 1 596735119
}
<<<<<
>>>>> Dumping cursor android.content.ContentResolver$CursorWrapperInner@3de45bbf
0 {
_id=24
album_art=Dummy path
artist=Charlie Parker
artist=Charlie Parker
numsongs=50
album_key= 1 M M 1 C - 1 E 3 - 7 ) K ? 9 1 G ) K = 1 K 1076433605
}
<<<<<
>>>>> Dumping cursor android.content.ContentResolver$CursorWrapperInner@22e9728c
0 {
_id=30
album_art=Dummy path
artist=Bill Evans Trio
artist=Bill Evans Trio
numsongs=10
album_key= M Q C / ) Y ) O O 7 1 S 9 ? ? ) 5 1 S ) C 5 Q ) K / -379248890
}
<<<<<
>>>>> Dumping cursor android.content.ContentResolver$CursorWrapperInner@22949dd5
0 {
_id=14
album_art=Dummy path
artist=Lester Young, Teddy Wilson Quartet
artist=Lester Young, Teddy Wilson Quartet
numsongs=7
album_key= G K 1 M ) C / O 1 / / Y 1537972582
}
<<<<<
>>>>> Dumping cursor android.content.ContentResolver$CursorWrapperInner@291c49ea
0 {
_id=31
album_art=Dummy path
artist=Ahmad Jamal
artist=Ahmad Jamal
numsongs=8
album_key= 1 M M 1 C - 1 E 3 ) 7 A ) / ; ) A ) ? G O -196083261
}
<<<<<
>>>>> Dumping cursor android.content.ContentResolver$CursorWrapperInner@348cf4db
0 {
_id=28
album_art=Dummy path
artist=Bill Evans Trio
artist=Bill Evans Trio
numsongs=10
album_key= 1 W G ? E K ) O 9 E C M 1375882484
}
<<<<<
>>>>> Dumping cursor android.content.ContentResolver$CursorWrapperInner@f012b78
0 {
_id=23
album_art=Dummy path
artist=Sonny Rollins
artist=Sonny Rollins
numsongs=5
album_key= M ) W E G 7 E C 1 - E ? E M M Q M 248432292
}
<<<<<
>>>>> Dumping cursor android.content.ContentResolver$CursorWrapperInner@158e4251
0 {
_id=17
album_art=Dummy path
artist=Wayne Shorter
artist=Wayne Shorter
numsongs=7
album_key= M G 1 ) = C E 1 S 9 ? 1951230391
}
<<<<<
>>>>> Dumping cursor android.content.ContentResolver$CursorWrapperInner@216d1ab6
0 {
_id=16
album_art=Dummy path
artist=Keith Jarrett & Charlie Haden
artist=Keith Jarrett & Charlie Haden
numsongs=9
album_key= ? ) M O / ) C - 1 1611567005
}
<<<<<
>>>>> Dumping cursor android.content.ContentResolver$CursorWrapperInner@185c03b7
0 {
_id=13
album_art=Dummy path
artist=Bill Evans & Shelly Manne
artist=Bill Evans & Shelly Manne
numsongs=6
album_key= 1 A G ) O 7 Y 1349167640
}
dumpCursorByAlbumId
上课
public void dumpCursorByAlbumId(String id){
String[] stringArray = {id};
final Cursor mCursor = ctx.getContentResolver().query(
MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, // Uri
new String[]{ // String[] projection (columns)
MediaStore.Audio.Albums._ID,
MediaStore.Audio.Albums.ALBUM_ART,
MediaStore.Audio.Albums.ARTIST,
MediaStore.Audio.Albums.ARTIST,
MediaStore.Audio.Albums.NUMBER_OF_SONGS,
MediaStore.Audio.Albums.ALBUM_KEY
},
MediaStore.Audio.Albums._ID + "=?", // String selection
stringArray, // String[] selectionArgs
null // sortOrder
);
if (mCursor.moveToFirst()) {
// dump each row in the cursor
// for(int i=0; i < stringArray.length; i++){
DatabaseUtils.dumpCursor(mCursor);
// mCursor.moveToNext();
//}
mCursor.close();
}
else {
mCursor.close();
}
}