优化
This commit is contained in:
@@ -9,6 +9,7 @@ import android.os.Build
|
|||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.provider.DocumentsContract
|
import android.provider.DocumentsContract
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
|
import androidx.core.provider.DocumentsContractCompat
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
@@ -32,7 +33,7 @@ object RealPathUtil {
|
|||||||
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider
|
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider
|
||||||
if (isExternalStorageDocument(uri)) {
|
if (isExternalStorageDocument(uri)) {
|
||||||
val docId = DocumentsContract.getDocumentId(uri)
|
val docId = DocumentsContract.getDocumentId(uri)
|
||||||
val split = docId.split(":").toTypedArray()
|
val split = docId.split(":")
|
||||||
val type = split[0]
|
val type = split[0]
|
||||||
if ("primary".equals(type, ignoreCase = true)) {
|
if ("primary".equals(type, ignoreCase = true)) {
|
||||||
return Environment.getExternalStorageDirectory().toString() + "/" + split[1]
|
return Environment.getExternalStorageDirectory().toString() + "/" + split[1]
|
||||||
@@ -67,6 +68,15 @@ object RealPathUtil {
|
|||||||
val selectionArgs = arrayOf(split[1])
|
val selectionArgs = arrayOf(split[1])
|
||||||
return getDataColumn(context, contentUri, selection, selectionArgs)
|
return getDataColumn(context, contentUri, selection, selectionArgs)
|
||||||
}
|
}
|
||||||
|
} else if (DocumentsContractCompat.isTreeUri(uri)) {
|
||||||
|
if (isExternalStorageDocument(uri)) {
|
||||||
|
val docId = DocumentsContract.getTreeDocumentId(uri)
|
||||||
|
val split = docId.split(":")
|
||||||
|
val type = split[0]
|
||||||
|
if ("primary".equals(type, ignoreCase = true)) {
|
||||||
|
return Environment.getExternalStorageDirectory().toString() + "/" + split[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if ("content".equals(uri.scheme, ignoreCase = true)) { // Return the remote address
|
} else if ("content".equals(uri.scheme, ignoreCase = true)) { // Return the remote address
|
||||||
return if (isGooglePhotosUri(uri)) uri.lastPathSegment
|
return if (isGooglePhotosUri(uri)) uri.lastPathSegment
|
||||||
else getDataColumn(context, uri, null, null)
|
else getDataColumn(context, uri, null, null)
|
||||||
|
|||||||
Reference in New Issue
Block a user