object UriUtil {
private fun getRealPathApi19Above(context: Context, uri: Uri): String? {
var filePath = ""
try {
// DocumentProvider
if (DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
val docId = DocumentsContract.getDocumentId(uri)
val split = docId.split(":").toTypedArray()
val type = split[0]
if ("primary".equals(type, ignoreCase = true)) {
return Environment.getExternalStorageDirectory().toString() + "/" + split[1]
}
} else if (isDownloadsDocument(uri)) {
val id = DocumentsContract.getDocumentId(uri)
val contentUri = ContentUris.withAppendedId(
Android 通过Uri获取真实文件路径
最新推荐文章于 2024-04-28 03:30:54 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)