Search code examples
javaandroidbitmapmediastoreandroid-9.0-pie

Android API 28 getBitmap throwing "no such column" error


On Android API 28, I'm trying to get the album art for a particular album using the albumID. The code throws the following error on getBitmap

android.database.sqlite.SQLiteException: no such column: _data (code 1 SQLITE_ERROR): , while compiling: SELECT _data FROM album_info WHERE (id=?)

The code below:

Uri imageUri_t = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, albumID);
origImage = MediaStore.Images.Media.getBitmap(contentResolver, imageUri_t);

The albumID is collected earlier using a cursor query to get the MediaStore.Audio.AudioColumns.ALBUM_ID column. I also tried with MediaStore.Audio.Albums_ID, but the same result happens.

It's worth noting that it works fine in API 29 and 30 using the newer loadThumnail introduced in API 29

origImage = contentResolver.loadThumbnail(imageUri_t, new android.util.Size(256, 256), null);

Solution

  • I figured it out. The error is a bit of misnomer, the actual error came because it couldn't find the path I was requesting. I replaced this line

    Uri imageUri_t = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, albumID);
    

    With this

    Uri imageUri_t = ContentUris.withAppendedId(Uri.parse("content://media/external/audio/albumart"), albumID);
    

    I assume either album art is kept in a different place on API 29 and below than API 30. Not sure, but hopefully this helps someone in the future who's equally confused as I was