优化
This commit is contained in:
@@ -42,7 +42,7 @@ class HandleFileContract :
|
|||||||
|
|
||||||
override fun parseResult(resultCode: Int, intent: Intent?): Result {
|
override fun parseResult(resultCode: Int, intent: Intent?): Result {
|
||||||
val uri = if (resultCode != RESULT_OK || intent?.data == null ||
|
val uri = if (resultCode != RESULT_OK || intent?.data == null ||
|
||||||
RealPathUtil.getPath(appCtx, intent.data!!)
|
RealPathUtil.getTreePath(intent.data!!)
|
||||||
?.startsWith(appCtx.externalFiles.parent!!) == true
|
?.startsWith(appCtx.externalFiles.parent!!) == true
|
||||||
) {
|
) {
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -86,6 +86,22 @@ object RealPathUtil {
|
|||||||
return uri.path
|
return uri.path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getTreePath(uri: Uri): String? {
|
||||||
|
if (!DocumentsContractCompat.isTreeUri(uri) || !isExternalStorageDocument(uri)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val docId = DocumentsContract.getTreeDocumentId(uri)
|
||||||
|
val split = docId.split(":")
|
||||||
|
if (split.size < 2) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val type = split[0]
|
||||||
|
if ("primary".equals(type, ignoreCase = true)) {
|
||||||
|
return Environment.getExternalStorageDirectory().toString() + "/" + split[1]
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of the data column for this Uri. This is useful for
|
* Get the value of the data column for this Uri. This is useful for
|
||||||
* MediaStore Uris, and other file-based ContentProviders.
|
* MediaStore Uris, and other file-based ContentProviders.
|
||||||
|
|||||||
Reference in New Issue
Block a user