From 8c8bb90de030d34d8fb0c67ad8d759304d8267cb Mon Sep 17 00:00:00 2001 From: JoxC <> Date: Mon, 5 Mar 2018 15:25:59 +0800 Subject: [PATCH 1/2] decode file url with percent escape for android and ios. --- .../cordova/plugins/fileopener2/FileOpener2.java | 12 ++---------- src/ios/FileOpener2.m | 4 ++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java index d4b2fff..b91e3d9 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -95,7 +95,7 @@ public class FileOpener2 extends CordovaPlugin { try { CordovaResourceApi resourceApi = webView.getResourceApi(); Uri fileUri = resourceApi.remapUri(Uri.parse(fileArg)); - fileName = this.stripFileProtocol(fileUri.toString()); + fileName = fileUri.getPath(); } catch (Exception e) { fileName = fileArg; } @@ -178,13 +178,5 @@ public class FileOpener2 extends CordovaPlugin { return appInstalled; } - private String stripFileProtocol(String uriString) { - if (uriString.startsWith("file://")) { - uriString = uriString.substring(7); - } else if (uriString.startsWith("content://")) { - uriString = uriString.substring(10); - } - return uriString; - } - } + diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 257a356..7eb08eb 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - (void) open: (CDVInvokedUrlCommand*)command { - NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]]; NSString *contentType = [command.arguments objectAtIndex:1]; BOOL showPreview = YES; @@ -53,7 +53,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. } dispatch_async(dispatch_get_main_queue(), ^{ - NSURL *fileURL = [NSURL URLWithString:path]; + NSURL *fileURL = [NSURL URLWithString:[path stringByRemovingPercentEncoding]]; localFile = fileURL.path; From e0fa3731d5e10bb5ed3deebc2454816ae0187934 Mon Sep 17 00:00:00 2001 From: JoxC Date: Mon, 12 Mar 2018 17:44:12 +0800 Subject: [PATCH 2/2] change android dependency com.android.support:support-v4:+ to com.android.support:support-v4:26.0.0-alpha1 --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 2ec207e..7822b53 100644 --- a/plugin.xml +++ b/plugin.xml @@ -31,7 +31,7 @@ - +