优化
Some checks failed
update fork / build (push) Has been cancelled
Test Build / prepare (push) Has been cancelled
Test Build / build (app, release) (push) Has been cancelled
Test Build / build (app, releaseA) (push) Has been cancelled
Test Build / prerelease (push) Has been cancelled
Test Build / lanzou (push) Has been cancelled
Test Build / test_Branch (push) Has been cancelled
Test Build / telegram (push) Has been cancelled

This commit is contained in:
Horis
2025-05-07 19:30:44 +08:00
parent d457f40d4a
commit f502d2cec4
2 changed files with 17 additions and 1 deletions

View File

@@ -42,7 +42,7 @@ class HandleFileContract :
override fun parseResult(resultCode: Int, intent: Intent?): Result {
val uri = if (resultCode != RESULT_OK || intent?.data == null ||
RealPathUtil.getPath(appCtx, intent.data!!)
RealPathUtil.getTreePath(intent.data!!)
?.startsWith(appCtx.externalFiles.parent!!) == true
) {
null

View File

@@ -86,6 +86,22 @@ object RealPathUtil {
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
* MediaStore Uris, and other file-based ContentProviders.