mirror of
https://gitee.com/shuto/cordova-plugin-file-opener2.git
synced 2025-01-31 12:02:49 +08:00
Merge pull request #196 from JoxC/master
decode file url with percent escape for android and ios.
This commit is contained in:
commit
70aa95bf1c
@ -95,7 +95,7 @@ public class FileOpener2 extends CordovaPlugin {
|
|||||||
try {
|
try {
|
||||||
CordovaResourceApi resourceApi = webView.getResourceApi();
|
CordovaResourceApi resourceApi = webView.getResourceApi();
|
||||||
Uri fileUri = resourceApi.remapUri(Uri.parse(fileArg));
|
Uri fileUri = resourceApi.remapUri(Uri.parse(fileArg));
|
||||||
fileName = this.stripFileProtocol(fileUri.toString());
|
fileName = fileUri.getPath();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fileName = fileArg;
|
fileName = fileArg;
|
||||||
}
|
}
|
||||||
@ -178,13 +178,5 @@ public class FileOpener2 extends CordovaPlugin {
|
|||||||
return appInstalled;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
|
|
||||||
- (void) open: (CDVInvokedUrlCommand*)command {
|
- (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];
|
NSString *contentType = [command.arguments objectAtIndex:1];
|
||||||
BOOL showPreview = YES;
|
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(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
NSURL *fileURL = [NSURL URLWithString:path];
|
NSURL *fileURL = [NSURL URLWithString:[path stringByRemovingPercentEncoding]];
|
||||||
|
|
||||||
localFile = fileURL.path;
|
localFile = fileURL.path;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user