API 29 Mediastore访问 [英] API 29 Mediastore Access

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

问题描述

我的应用程序在android mediastore中创建播放列表.包括28在内的api一切都很好,但是api 29似乎需要其他权限.插入新的播放列表名称和ID不会出现问题.当涉及插入曲目ID和播放顺序时,将引发访问权限异常.在验证Uri时,我发现当API 29的resolver.insert出现时,异常错误是:

My app creates playlists in the android mediastore. All is well for api's including 28 however, api 29 seems to require additional permissions. Inserting a new playlist name and id works without issue. When it comes to inserting track id and play order, an access permission exception is thrown. In verifying the Uri, i found that when resolver.insert for API 29 the exception error is:

java.lang.SecurityException: myapp_name has no access to content://media/external_primary/audio/media/146

代码:

Uri exturi = MediaStore.Audio.Playlists.Members.getContentUri("external", playlist_id);
// exturi : content://media/external/audio/playlists/227/members

// values : audio_id=146 play_order=0
values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, play_order);
values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, audio_id);

try {
    resolver.insert(exturi, values);
} catch (Exception e) {
    e.printStackTrace();
}

奇怪的是,尽管可以在Mediastore中插入新的播放列表,但是添加曲目(track_id,播放顺序)会导致访问权限错误

Strange thing is that although inserting a new playlist into Mediastore works but adding tracks (track_id, play order) gives an access permission error

如何解决API 29的此异常错误?

2021年2月更新:向前迈出了一小步,我很确定我需要为原始uri获取Documenturi,但仍然会给我访问错误.因此,问题不在于访问曲目,而在于uri本身.

Update Feb 2021: a small step forward, I am pretty sure I need to get Documenturi for the original uri but still gives me the access error. So the issue does not lie with accessing the tracks but with the uri itself.

doc_uri = MediaStore.getDocumentUri(context,playlist_members_uri);
java.lang.SecurityException: com.flyingdutchman.newplaylistmanager has no access to content://media/external/audio/playlists/130/members

推荐答案

我认为这是Android 10的错误,因此我在此处提交了报告:

I think this is an Android 10 bug, so I've filed a report here: https://issuetracker.google.com/issues/147619577 (includes instructions for an emulator test case to reproduce it if that interests you). Please consider starring it to let the Android team know that it affects you.

据我所知,它仅会影响外部"存储上的文件,例如/storage/XXXX-XXXX

From what I can tell, it only affects files on 'external' storage, like sdcards mounted on /storage/XXXX-XXXX

同时,我的一些用户能够成功应用的唯一解决方法是将他们的音乐文件移动到内部存储设备(重新启动并等待媒体扫描完成,以确保MediaStore处于最新状态).日期).

In the meantime, the only fix that some of my users were able to successfully apply is to move their music files to the internal storage (reboot and wait for the media scan to finish to be sure that MediaStore is up-to-date).

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

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