问题
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