How to retrieve a single media file from external storage using Mediastore?

巧了我就是萌 提交于 2021-01-29 08:10:14

问题


Before API 29, we could have easily retrieved a media file from external storage using these lines of code.

val dirName = Environment.getExternalStorageDirectory().absolutePath + "/$appName/"
val fileName = "$appName_$timeStamp.$extension"
val dir = File(dirName)
val file = File(dir, fileName)

But I was unable to find a code snippet which can achieve the same thing using Mediastore API. Since getExternalStorageDirectory is deprecated in API 29, I don't know how to do. I have searched about this, and found some code which can access all the images stored in a directory and like that, using query kind of mechanism. In this guide also they only mentioned that we can use File API, but did not provide any code sample.

Can anyone help me out with this please.

Also inform me, if there is any error in the above snippet, or if it is wrong way to do. Thanks in advance.

来源:https://stackoverflow.com/questions/64730774/how-to-retrieve-a-single-media-file-from-external-storage-using-mediastore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!