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。

相关内容

热门资讯

透视新版!aapoker怎么选... 透视新版!aapoker怎么选牌(透视)辅助(都是是真的有挂);1、打开软件启动之后找到中间准星的标...
透视存在!德普之星私人局辅助免... 透视存在!德普之星私人局辅助免费(透视)透视(果然真的是有挂)1、完成德普之星私人局辅助免费的残局,...
透视科技!aapoker ai... 透视科技!aapoker ai插件(透视)透视方法(总是真的有挂)1、首先打开aapoker ai插...
透视私人局!德普之星私人局透视... 透视私人局!德普之星私人局透视(透视)透视软件免费入口官网(其实有挂)德普之星私人局透视是一种具有地...
透视插件!aapoker怎么设... 透视插件!aapoker怎么设置提高好牌几率(透视)透视软件(都是存在有挂)1)aapoker怎么设...
透视透视!德普之星辅助工具如何... 透视透视!德普之星辅助工具如何打开(透视)透视(真是存在有挂);1、德普之星辅助工具如何打开机器人多...
透视黑科技!aapoker万能... 透视黑科技!aapoker万能辅助器(透视)插件下载(切实存在有挂)1、在aapoker万能辅助器a...
透视辅助!德扑圈透视(透视)透... 透视辅助!德扑圈透视(透视)透视辅助插件(一直真的是有挂);1、在德扑圈透视ai机器人技巧中,中转单...
透视代打!aapoker怎么提... 透视代打!aapoker怎么提高中牌率(透视)透视脚本入口(原来真的是有挂)暗藏猫腻,小编详细说明a...
透视透视!德普之星私人局辅助器... 透视透视!德普之星私人局辅助器(透视)私人局辅助器(真是真的是有挂)1、德普之星私人局辅助器ai辅助...