From 4f4f8564dff361cb7543a9670ecc46f273888b59 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Wed, 24 Jun 2026 14:38:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(webview):=20=E6=81=A2=E5=A4=8D=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=80=89=E6=8B=A9=E5=99=A8=E4=BD=BF=E7=94=A8=20ACTION?= =?UTF-8?q?=5FGET=5FCONTENT=20=E4=BF=9D=E6=8C=81=E5=8E=9F=E6=9C=89=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ACTION_OPEN_DOCUMENT 打开的是 SAF 文档选择器,缺少文档、图片、最近等 快捷入口,体验不及 ACTION_GET_CONTENT 的系统底部弹窗。 真正修复 vivo/OPPO URI 权限问题的是 copyUriToWebViewCache(),选择文件后 将内容复制到本地 file:// 路径再传给 WebView,与 Intent 类型无关。 故改回 ACTION_GET_CONTENT,恢复原有选择器界面。 Co-Authored-By: Claude Sonnet 4.6 --- .../main/java/com/xuqm/sdk/webview/XWebViewView.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sdk-webview/src/main/java/com/xuqm/sdk/webview/XWebViewView.kt b/sdk-webview/src/main/java/com/xuqm/sdk/webview/XWebViewView.kt index 9ff1676..e63d677 100644 --- a/sdk-webview/src/main/java/com/xuqm/sdk/webview/XWebViewView.kt +++ b/sdk-webview/src/main/java/com/xuqm/sdk/webview/XWebViewView.kt @@ -45,6 +45,7 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver import androidx.core.content.ContextCompat import androidx.core.content.FileProvider +import android.provider.MediaStore import com.xuqm.sdk.file.FileDownloadDestination import com.xuqm.sdk.file.FileSDK import kotlinx.coroutines.Dispatchers @@ -89,6 +90,10 @@ internal fun resolvePickerMimeTypes(acceptTypes: Array): Array { // ACTION_GET_CONTENT contract supporting multiple MIME types via EXTRA_MIME_TYPES. internal class GetContentWithMimeTypes : ActivityResultContract, Uri?>() { override fun createIntent(context: Context, input: Array): Intent = + // Use ACTION_GET_CONTENT to preserve the familiar system file picker UI (bottom sheet + // with Documents/Images/Recent shortcuts). URI permission issues on vivo/OPPO are + // handled downstream by copyUriToWebViewCache(), which copies the file to a local + // cache path before passing it to WebView — so the intent type does not matter. Intent(Intent.ACTION_GET_CONTENT).apply { addCategory(Intent.CATEGORY_OPENABLE) if (input.size == 1) { @@ -272,14 +277,14 @@ internal fun storagePermissionsGranted(context: Context, acceptMimes: Array if (cursor.moveToFirst()) cursor.getString(0) else null } ?: runCatching { context.contentResolver.query( - uri, arrayOf(android.provider.MediaStore.MediaColumns.DATA), null, null, null + uri, arrayOf(MediaStore.MediaColumns.DATA), null, null, null )?.use { cursor -> if (cursor.moveToFirst()) cursor.getString(0)?.substringAfterLast('/') else null } @@ -298,7 +303,7 @@ internal fun copyUriToWebViewCache(context: Context, uri: Uri, mimeType: String? val bytesRead = context.contentResolver.openInputStream(uri)?.use { input -> dest.outputStream().use { out -> input.copyTo(out) } - } ?: return null // openInputStream returned null — URI unreadable + } ?: return null android.util.Log.d("XWV", "copyUriToWebViewCache: $uri → ${dest.name} ($bytesRead bytes)") Uri.fromFile(dest)