From d3febf7c7fc9f7ee6b35b9139d460684469398a2 Mon Sep 17 00:00:00 2001 From: jiangwei Date: Thu, 13 Jul 2023 11:20:41 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9Amissing=20content=20uri=20handler?= =?UTF-8?q?=20in=20WebViewAssetLoader.PathHandler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/android/FileUtils.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java index de973da8..cf0839ca 100644 --- a/src/android/FileUtils.java +++ b/src/android/FileUtils.java @@ -1313,6 +1313,9 @@ public CordovaPluginPathHandler getPathHandler() { } else if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("assets"))) { targetFileSystem = "assets"; } + else if (path.startsWith(LocalFilesystemURL.fsNameToCdvKeyword("content"))) { + targetFileSystem = "content"; + } boolean isAssetsFS = targetFileSystem == "assets"; @@ -1339,6 +1342,14 @@ public CordovaPluginPathHandler getPathHandler() { } try { + if(targetFileSystem == "content") { + ContentResolver cr = webView.getContext().getContentResolver(); + Uri uri = Uri.parse(fileTarget); + InputStream fileIS = new FileInputStream(cr.openFileDescriptor(uri, "r").getFileDescriptor()); + String fileMimeType = cr.getType(uri); + + return new WebResourceResponse(fileMimeType, null, fileIS); + } InputStream fileIS = !isAssetsFS ? new FileInputStream(file) : webView.getContext().getAssets().open(fileTarget);