,可以通过以下步骤进行:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
并在运行时请求权限:
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
}
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.DATA};
String selection = MediaStore.Audio.Media.IS_MUSIC + "!= 0";
String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";
Cursor cursor = getContentResolver().query(uri, projection, selection, null, sortOrder);
if (cursor != null) {
while (cursor.moveToNext()) {
String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
// 处理获取到的音频文件信息
}
cursor.close();
}
推荐的腾讯云相关产品:腾讯云对象存储(COS)
请注意,以上答案仅供参考,具体实现方式可能因开发环境、需求等因素而有所不同。
领取专属 10元无门槛券
手把手带您无忧上云