Android 10 MediaStore API changes

孤街浪徒 提交于 2020-01-24 16:24:31

问题


Uri uri = MediaStore.Audio.Artists.Albums.getContentUri("external", 
artistId);

String[] projection = new String[] {BaseColumns._ID};

Cursor cursor = 
mContext.getApplicationContext().getContentResolver().query
(uri,
projection,
null,
null,
null);

Prior to Android 10, BaseColumns._ID was returning album_id and now in 10, it returns some random Id.

When I passed projection as null and retrieved all column names below are the column name that I get. This is in Android 10. [numsongs, artist, numsongs_by_artist, album, album_art, album_key, artist_id, maxyear, minyear, album_id]

There is no _id column which was there in below Android 10.

To get the album_id in 10 I had to use below projection

String[] projection = new String[] 
{MediaStore.Audio.Artists.Albums.ALBUM_ID};

For the same Uri below are the available columns that I get in below Android 10. [album_art, maxyear, minyear, artist, album, artist_key, numsongs_by_artist, _id, numsongs, album_key, artist]

Here there is no album_id column, _id was returning album_id. Which now in 10 is not available.

And now I need to have different codes to get the album id, one for Android 10 and one for below Android 10.

And these changes are nowhere listed in Android 10 behavioral changes. This is very critical changes for us, a small change like this can break our entire app which is used by 1.5M people per day.

How can somebody change like this and not let developers know anything about it? (OR) Is there something that I am missing to look for in the docs. (or) How to do I track these changes?


回答1:


Below android Q, for MediaStore.Audio.Artists.Albums.getContentUri("external", artistId) uri, album id was available in column BaseColumns._ID, and in android Q this column is not available, but still returns some random number which is not album id.

We have to use MediaStore.Audio.Artists.Albums.ALBUM_ID to get the album id in Android Q. But this doesn't work for below android Q, as this column is not available in that. And hence we have to use two different versions to refer the album id.

if (Build.VERSION.SDK_INT >= 29) {
    return MediaStore.Audio.Artists.Albums.ALBUM_ID;
}else{
    return BaseColumns._ID;
}    

Edit 1 : Had a raised an issue with google about the same. https://issuetracker.google.com/issues/140508535 . Google has said it is fixed and will be available in next release.



来源:https://stackoverflow.com/questions/57799515/android-10-mediastore-api-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!