AndroidStudio中Mediastore.Audio.Media.DATA已被弃用,是否有替代方案?
创始人
2024-08-21 01:00:05
0

在Android 10及更高版本上,getAbsolutePath()方法无法访问非应用内部存储的文件,因此需要使用MediaStore API。可以使用以下代码示例:

//获得属于MediaStore音频媒体的uri。 Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

//创建查询,指定uri并请求音频文件名 Cursor cursor = getContentResolver().query(uri, null, null, null, MediaStore.Audio.Media.DISPLAY_NAME + " ASC");

if(cursor != null){ while(cursor.moveToNext()){ //获取音频id int id = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media._ID)); //获取音频文件名 String name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)); //获取音频文件路径 String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.RELATIVE_PATH)); if (path == null) { path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA)); } //do something with the audio file data } cursor.close(); }

使用该方法,我们可以访问非应用私有目录中的音频文件,而不需要使用Deprecated的Mediastore.Audio.Media.DATA。

相关内容

热门资讯

一分钟辅助!pokemmo脚本... 一分钟辅助!pokemmo脚本手机版,aapoker怎么提高中牌率,阶段教程(有挂解密)暗藏猫腻,小...
四分钟辅助!we-poker有... 四分钟辅助!we-poker有人玩吗,wepoker免费脚本咨询,演示教程(有挂教程)wepoker...
八分钟辅助!aa poker辅... 八分钟辅助!aa poker辅助,pokemmo内置修改器,方式教程(证实有挂)1、完成pokemm...
第2分钟辅助!智星菠萝透视,h... 第2分钟辅助!智星菠萝透视,hhpoker到底可以作弊码,策略教程(有挂规律)1、hhpoker到底...
第1分钟辅助!wepoker怎... 第1分钟辅助!wepoker怎么发冤家牌,pokemomo辅助软件,办法教程(有挂解惑)1、wepo...
第1分钟辅助!德普之星辅助工具... 第1分钟辅助!德普之星辅助工具如何打开,德州局hhpoker,总结教程(有挂辅助)1、进入游戏-大厅...
第九分钟辅助!wepoker私... 第九分钟辅助!wepoker私人局俱乐部,德州圈脚本,妙招教程(有挂分享)暗藏猫腻,小编详细说明we...
第四分钟辅助!wpk模拟器,h... 第四分钟辅助!wpk模拟器,hhpoker辅助靠谱吗,技法教程(有挂讲解)1、完成hhpoker辅助...
第十分钟辅助!wepoker轻... 第十分钟辅助!wepoker轻量版辅助,wpk德州局透视,模板教程(有挂方针)wepoker轻量版辅...
七分钟辅助!wepoker透视... 七分钟辅助!wepoker透视最简单三个步骤,aapoker透视脚本入口,妙计教程(有挂秘籍)1、许...