Android 10 MediaStore API更改 [英] Android 10 MediaStore API changes

查看:241
本文介绍了Android 10 MediaStore API更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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);

在Android 10之前,BaseColumns._ID返回的是album_id,现在在10中,它返回了一些随机ID.

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

当我将投影传递为null并检索到下面的所有列名时,就是我得到的列名.这是在Android 10中. [numsongs,艺术家,numsongs_by_artist,专辑,album_art,专辑_key,artist_id,maxyear,minyear,album_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]

Android 10以下没有_id列.

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

要获得10张专辑ID,我必须在投影下面使用

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

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

对于同一Uri,以下是我在Android 10下获得的可用列. [专辑艺术,最大年份,最小年份,艺术家,专辑,artist_key,numsongs_by_artist,_id,numsongs,专辑密钥,艺术家]

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]

此处没有album_id列,_id正在返回album_id.现在10个中的哪个不可用.

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

现在我需要使用不同的代码来获取专辑ID,一个用于Android 10,一个用于Android 10以下.

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

并且这些更改未在Android 10行为更改中列出.对于我们来说,这是非常关键的更改,像这样的小更改可能会破坏每天有150万用户使用的整个应用程序.

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?

推荐答案

在android Q下,对于MediaStore.Audio.Artists.Albums.getContentUri("external",artistId)uri,专辑ID在BaseColumns._ID列中可用,并且在android Q中此列不可用,但仍返回一些不是专辑ID的随机数.

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.

我们必须使用MediaStore.Audio.Artists.Albums.ALBUM_ID来获取Android Q中的专辑ID.但这不适用于android Q以下,因为该列在其中不可用.因此,我们必须使用两个不同的版本来引用专辑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;
}    

与google提出了一个差不多的问题. https://issuetracker.google.com/issues/140508535 .谷歌表示已修复,将在下一版本中提供.

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.

这篇关于Android 10 MediaStore API更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆