我正在尝试访问并列出android Q或10上的所有音乐文件。我可以使用光标并添加此投影
private static final String[] EXTERNAL_COLUMNS = new String[]{
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.IS_RINGTONE,
MediaStore.Audio.Media.IS_ALARM,
MediaStore.Audio.Media.IS_NOTIFICATION,
MediaStore.Audio.Media.IS_MUSIC,
"\"" + MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + "\""
};但它一直工作到api级别28。在安卓10上,它显示的是Caused by: java.lang.IllegalArgumentException: Invalid column "content://media/external/audio/media"。
我在cursorLoader中添加了这个投影。我知道Android 10API级别有一些行为上的变化,但这件事真的把我吓坏了。有没有人能帮我。提前谢谢。
发布于 2019-09-09 21:13:52
用MediaStore.Audio.AudioColumns替换MediaStore.Audio.Media
发布于 2019-12-24 12:32:20
我只使用:-
private static final String[] EXTERNAL_COLUMNS = new String[]{
MediaStore.Audio.Media._ID,
};作为列,并将null作为投影传递。
然后通过以下方式为每个文件创建uri:
Uri uri=ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id)之后,我列出了所有的uri,并通过java获取文件的所有其他数据。它起作用了,感谢@commonsWare。这看起来很难,但其实很容易,试一试吧!
我正在添加图像获取代码以供参考
fun getAllDataPath(activity: Activity): MutableList<Uri> {
val uriExternal: Uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
val cursor: Cursor?
val columnIndexID: Int
val listOfAllImages: MutableList<Uri> = mutableListOf()
val projection = arrayOf(MediaStore.Images.Media._ID)
var imageId: Long
cursor = activity.contentResolver.query(uriExternal, projection, null, null, null)
if (cursor != null) {
columnIndexID = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID)
while (cursor.moveToNext()) {
imageId = cursor.getLong(columnIndexID)
val uriImage = Uri.withAppendedPath(uriExternal, "" + imageId)
listOfAllImages.add(uriImage)
}
cursor.close()
}
return listOfAllImages
}请将图片转换为音乐,以供参考。
谢谢
https://stackoverflow.com/questions/57854562
复制相似问题