I am queryng MediaStore.Audio.Media
for a song ID, using the ID to find the album art URI, and then downloading the album art if the URI is null, and finally updating MediaStore.Audio.Albums
with the new image URI. I am not able to figure out the last part.
Here I am getting the cursor with GetCursor()
method
private Cursor GetCursor() {
Uri contentURI = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.ALBUM_ID};
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
String order = MediaStore.Audio.Media.TITLE + " ASC";
final Cursor mCursor = getContentResolver().query(contentURI, projection, selection, null, order);// Run getContentResolver query
return mCursor;
}
Here I am adding the album art URI to songObject
with GetAlbumArtURI()
String[] albumID = {mCursor.getString(5)};
songObject.albumArtURI = GetAlbumArtURI(albumID);
Here is GetAlbumArtURI()
method
private String GetAlbumArtURI(String[] albumID) {
final Cursor mCursor = getContentResolver().query(
MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Audio.Albums.ALBUM_ART},
MediaStore.Audio.Albums._ID + "=?",
albumID,
null
);
if (mCursor.moveToFirst()) {
String var = mCursor.getString(mCursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
//DatabaseUtils.dumpCursor(mCursor);
mCursor.close();
return var;
}
else {
mCursor.close();
return null;
}
}
And here I test if the songObject.albumArtURI
is null, download the image, and record the URI in the meta data
if (songObject.albumArtURI == null){
String anotherURI = downloadImageReturnURI();
ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Albums.ALBUM_ART, anotherURI);
// And now I don't know what to do
}
So now, how can I add the new URI back to ALBUM_ART column? Something along these lines?
Uri uri = MediaStore.Audio.Albums.getContentUriForPath(newSoundFile.getAbsolutePath());
Uri newUri = getContentResolver().insert(uri, values);
The problem is that I am not trying to update values in MediaStore.Audio.Media
but in MediaStore.Audio.Albums