From cc90ff7e70211420d1297213433ab7a493d8738b Mon Sep 17 00:00:00 2001 From: Gillardo Date: Fri, 30 Sep 2016 11:35:29 +0100 Subject: [PATCH 01/76] Update FileOpener2.m Doesnt work on iOS 10 --- src/ios/FileOpener2.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index b9f67fa..3ce4579 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -43,7 +43,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. dispatch_async(dispatch_get_main_queue(), ^{ // TODO: test if this is a URI or a path - NSURL *fileURL = [NSURL URLWithString:path]; + NSURL *fileURL = [NSURL fileURLWithPath:path]; localFile = fileURL.path; From d1fab6d457a91e1bcd43b183ad1aa26c6591db35 Mon Sep 17 00:00:00 2001 From: pwlin Date: Tue, 4 Oct 2016 19:21:31 +0200 Subject: [PATCH 02/76] Revert "Fixed for iOS 10" --- src/ios/FileOpener2.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 3ce4579..b9f67fa 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -43,7 +43,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. dispatch_async(dispatch_get_main_queue(), ^{ // TODO: test if this is a URI or a path - NSURL *fileURL = [NSURL fileURLWithPath:path]; + NSURL *fileURL = [NSURL URLWithString:path]; localFile = fileURL.path; From e2ea30f9734b529a2164e507cf842fa2eb4dc6d3 Mon Sep 17 00:00:00 2001 From: J3r0M3D3V Date: Wed, 12 Oct 2016 12:50:55 +0200 Subject: [PATCH 03/76] Update fileOpener2Proxy.js It didn't work on windows, mainly due to uri/path problems. I fixed it, + some changes like an error on callback. --- src/windows/fileOpener2Proxy.js | 59 ++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index 57ca558..e74077e 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -4,18 +4,46 @@ var schemes = [ { protocol: 'ms-app', getFile: getFileFromApplicationUri }, - { protocol: 'file:///', getFile: getFileFromFileUri } + { protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile ] - function getFileFromApplicationUri(uri) { - var applicationUri = new Windows.Foundation.Uri(uri); + function nthIndex(str, pat, n) { + var L = str.length, i = -1; + while (n-- && i++ < L) { + i = str.indexOf(pat, i); + if (i < 0) break; + } + return i; + } - return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); + function getFileFromApplicationUri(uri) { + /* bad path from a file entry due to the last '//' + example: ms-appdata:///local//path/to/file + */ + var index = nthIndex(uri, "//", 3); + var newUri = uri.substr(0, index) + uri.substr(index + 1); + + var applicationUri = new Windows.Foundation.Uri(newUri); + + return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri);; } function getFileFromFileUri(uri) { - var path = Windows.Storage.ApplicationData.current.localFolder.path + - uri.substr(8); + /* uri example: + cdvfile://localhost/persistent|temporary|another-fs-root/path/to/file + */ + var indexFrom = nthIndex(uri, "/", 3) + 1; + var indexTo = nthIndex(uri, "/", 4); + var whichFolder = uri.substring(indexFrom, indexTo); + var filePath = uri.substr(indexTo + 1); + var path = "\\" + filePath; + + if (whichFolder == "persistent") { + path = Windows.Storage.ApplicationData.current.localFolder.path + path; + } + else { //temporary, note: no roaming management + path = Windows.Storage.ApplicationData.current.temporaryFolder.path + path; + } return getFileFromNativePath(path); } @@ -39,23 +67,22 @@ module.exports = { open: function (successCallback, errorCallback, args) { + var path = args[0]; var getFile = getFileLoaderForScheme(path); - + getFile(path).then(function (file) { var options = new Windows.System.LauncherOptions(); - - Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { - if (success) { - successCallback(); - } else { - errorCallback(); - } + + Windows.System.Launcher.launchFileAsync(file, options).done(function (success) { + successCallback(); + }, function (error) { + errorCallback(error); }); - }, function (errror) { - console.log("Error abriendo el archivo"); + }, function (error) { + console.log("Error while opening the file: "+error); }); } From 91064a039097f48fc6a9672a4cbf916e504a2849 Mon Sep 17 00:00:00 2001 From: J3r0M3D3V Date: Wed, 12 Oct 2016 13:54:26 +0200 Subject: [PATCH 04/76] Update fileOpener2Proxy.js add another errorCallBack --- src/windows/fileOpener2Proxy.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index e74077e..48f7332 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -83,6 +83,7 @@ }, function (error) { console.log("Error while opening the file: "+error); + errorCallback(error); }); } From bea7625d8fbff198df92d47d8e78cd6dadd14989 Mon Sep 17 00:00:00 2001 From: J3r0M3D3V Date: Wed, 12 Oct 2016 17:05:00 +0200 Subject: [PATCH 05/76] Update fileOpener2Proxy.js double ; --- src/windows/fileOpener2Proxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index 48f7332..69d34ee 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -25,7 +25,7 @@ var applicationUri = new Windows.Foundation.Uri(newUri); - return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri);; + return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); } function getFileFromFileUri(uri) { From d2ccb221e95cd3613540ad2b9f0ec37cacb9fc65 Mon Sep 17 00:00:00 2001 From: J3r0M3D3V Date: Thu, 13 Oct 2016 11:04:11 +0200 Subject: [PATCH 06/76] Update fileOpener2Proxy.js then > done --- src/windows/fileOpener2Proxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index 69d34ee..ce2dee6 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -75,7 +75,7 @@ getFile(path).then(function (file) { var options = new Windows.System.LauncherOptions(); - Windows.System.Launcher.launchFileAsync(file, options).done(function (success) { + Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { successCallback(); }, function (error) { errorCallback(error); From b25124554de42788dfb66720e7e0d4fcff4ca140 Mon Sep 17 00:00:00 2001 From: pwlin Date: Wed, 23 Nov 2016 16:40:25 +0100 Subject: [PATCH 07/76] Upped --- README.md | 2 +- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4393066..ff77cf5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Contributors ------------ -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc) +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V) A File Opener Plugin for Cordova (The Original Version) diff --git a/package.json b/package.json index 4dd03ac..6be6dd8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.2", + "version": "2.0.3", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index d6f67eb..3a50e8d 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From 3ee95e5bcbe105f8a9baa57894cb2a7082aba59a Mon Sep 17 00:00:00 2001 From: pwlin Date: Wed, 23 Nov 2016 16:45:25 +0100 Subject: [PATCH 08/76] version 2.0.3 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ff77cf5..60855fc 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.2 +Current Version: 2.0.3 ---------------- Requirements From 70e610e465d774d18a592140a0bbf745f4ee09e3 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Fri, 27 Jan 2017 15:01:33 -0500 Subject: [PATCH 09/76] Fixes https://github.com/pwlin/cordova-plugin-file-opener2/issues/84 --- plugin.xml | 15 +++++++- .../plugins/fileopener2/FileOpener2.java | 36 +++++++++++++++---- .../plugins/fileopener2/FileProvider.java | 7 ++++ src/android/res/xml/opener_paths.xml | 4 +++ 4 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 src/android/io/github/pwlin/cordova/plugins/fileopener2/FileProvider.java create mode 100644 src/android/res/xml/opener_paths.xml diff --git a/plugin.xml b/plugin.xml index 3a50e8d..d0961bc 100644 --- a/plugin.xml +++ b/plugin.xml @@ -16,6 +16,7 @@ + @@ -24,6 +25,18 @@ + + + + + + @@ -46,7 +59,7 @@ - + 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 8a060ef..b330b4f 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -23,15 +23,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package io.github.pwlin.cordova.plugins.fileopener2; import java.io.File; +import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.net.Uri; -//import android.util.Log; +import android.os.Build; + +import io.github.pwlin.cordova.plugins.fileopener2.FileProvider; import org.apache.cordova.CordovaPlugin; import org.apache.cordova.CallbackContext; @@ -42,7 +47,7 @@ public class FileOpener2 extends CordovaPlugin { /** * Executes the request and returns a boolean. - * + * * @param action * The action to execute. * @param args @@ -54,7 +59,7 @@ public class FileOpener2 extends CordovaPlugin { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("open")) { this._open(args.getString(0), args.getString(1), callbackContext); - } + } else if (action.equals("uninstall")) { this._uninstall(args.getString(0), callbackContext); } @@ -93,8 +98,25 @@ public class FileOpener2 extends CordovaPlugin { try { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setDataAndType(path, contentType); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + if(Build.VERSION.SDK_INT >= 24){ + + Context context = cordova.getActivity().getApplicationContext(); + path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); + intent.setDataAndType(path, contentType); + intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); + //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + + List infoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); + for (ResolveInfo resolveInfo : infoList) { + String packageName = resolveInfo.activityInfo.packageName; + context.grantUriPermission(packageName, path, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); + } + } + else { + intent.setDataAndType(path, contentType); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + } /* * @see * http://stackoverflow.com/questions/14321376/open-an-activity-from-a-cordovaplugin @@ -115,7 +137,7 @@ public class FileOpener2 extends CordovaPlugin { callbackContext.error(errorObj); } } - + private void _uninstall(String packageId, CallbackContext callbackContext) throws JSONException { if (this._appIsInstalled(packageId)) { Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE); @@ -130,7 +152,7 @@ public class FileOpener2 extends CordovaPlugin { callbackContext.error(errorObj); } } - + private boolean _appIsInstalled(String packageId) { PackageManager pm = cordova.getActivity().getPackageManager(); boolean appInstalled = false; diff --git a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileProvider.java b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileProvider.java new file mode 100644 index 0000000..cc6b18d --- /dev/null +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileProvider.java @@ -0,0 +1,7 @@ +package io.github.pwlin.cordova.plugins.fileopener2; + +/* + * http://stackoverflow.com/questions/40746144/error-with-duplicated-fileprovider-in-manifest-xml-with-cordova/41550634#41550634 + */ +public class FileProvider extends android.support.v4.content.FileProvider { +} diff --git a/src/android/res/xml/opener_paths.xml b/src/android/res/xml/opener_paths.xml new file mode 100644 index 0000000..a6ce6d3 --- /dev/null +++ b/src/android/res/xml/opener_paths.xml @@ -0,0 +1,4 @@ + + + + From cd66d6597b07b7c6254265733b308b00ca6ca822 Mon Sep 17 00:00:00 2001 From: pwlin Date: Fri, 27 Jan 2017 23:25:39 +0100 Subject: [PATCH 10/76] Upped the version to 2.0.4 --- README.md | 4 ++-- package.json | 2 +- plugin.xml | 2 +- .../plugins/fileopener2/FileProvider.java | 22 +++++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 60855fc..cff03c1 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ Contributors ------------ -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V) +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree) A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.3 +Current Version: 2.0.4 ---------------- Requirements diff --git a/package.json b/package.json index 6be6dd8..995c369 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.3", + "version": "2.0.4", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index d0961bc..861eafb 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) diff --git a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileProvider.java b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileProvider.java index cc6b18d..c9d4984 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileProvider.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileProvider.java @@ -1,3 +1,25 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013 pwlin - pwlin05@gmail.com + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ package io.github.pwlin.cordova.plugins.fileopener2; /* From 916958c9601ccb085076a798236f5448a93155f7 Mon Sep 17 00:00:00 2001 From: pwlin Date: Tue, 31 Jan 2017 00:33:34 +0100 Subject: [PATCH 11/76] Fixed #90 - Upped the version to 2.0.5 --- README.md | 236 +++++++++++++++++++++++++-------------------------- package.json | 2 +- plugin.xml | 4 +- 3 files changed, 121 insertions(+), 121 deletions(-) diff --git a/README.md b/README.md index cff03c1..1268333 100644 --- a/README.md +++ b/README.md @@ -1,118 +1,118 @@ -Contributors ------------- -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree) - - -A File Opener Plugin for Cordova (The Original Version) -========================== -This plugin will open a file on your device file system with its default application. - -Current Version: 2.0.4 ----------------- - -Requirements -------------- -- Android 4 or higher / iOS 6 or higher / WP8 -- Cordova 3.0 or higher - -Installation -------------- - cordova plugin add cordova-plugin-file-opener2 - -Usage ------- - cordova.plugins.fileOpener2.open( - filePath, - fileMIMEType, - { - error : function(){ }, - success : function(){ } - } - ); - -Examples --------- -Open an APK install dialog: - - cordova.plugins.fileOpener2.open( - '/sdcard/Download/gmail.apk', - 'application/vnd.android.package-archive' - ); - -Open a PDF document with the default PDF reader and optional callback object: - - cordova.plugins.fileOpener2.open( - '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf - 'application/pdf', - { - error : function(e) { - console.log('Error status: ' + e.status + ' - Error message: ' + e.message); - }, - success : function () { - console.log('file opened successfully'); - } - } - ); - -Notes ------- - -- For properly opening _any_ file, you must already have a suitable reader for that particular file type installed on your device. Otherwise this will not work. - - -- [It is reported](https://github.com/pwlin/cordova-plugin-file-opener2/issues/2#issuecomment-41295793) that in iOS, you might need to remove `` from your `config.xml` - -- If you are wondering what MIME-type should you pass as the second argument to `open` function, [here is a list of all known MIME-types](http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co) - - -Additional Android Functions ------------------------------ -####The following functions are available in Android platform - -###.uninstall(_packageId, callbackContext_) -Uninstall a package with its id. - - cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', { - error : function(e) { - console.log('Error status: ' + e.status + ' - Error message: ' + e.message); - }, - success : function() { - console.log('Uninstall intent activity started.'); - } - }); - -###.appIsInstalled(_packageId, callbackContext_) -Check if an app is already installed. - - cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', { - success : function(res) { - if (res.status === 0) { - console.log('Adobe Reader is not installed.'); - } else { - console.log('Adobe Reader is installed.') - } - } - }); - -LICENSE --------- -The MIT License (MIT) - -Copyright (c) 2013 pwlin - pwlin05@gmail.com - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Contributors +------------ +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/) + + +A File Opener Plugin for Cordova (The Original Version) +========================== +This plugin will open a file on your device file system with its default application. + +Current Version: 2.0.5 +---------------- + +Requirements +------------- +- Android 4 or higher / iOS 6 or higher / WP8 +- Cordova 3.0 or higher + +Installation +------------- + cordova plugin add cordova-plugin-file-opener2 + +Usage +------ + cordova.plugins.fileOpener2.open( + filePath, + fileMIMEType, + { + error : function(){ }, + success : function(){ } + } + ); + +Examples +-------- +Open an APK install dialog: + + cordova.plugins.fileOpener2.open( + '/sdcard/Download/gmail.apk', + 'application/vnd.android.package-archive' + ); + +Open a PDF document with the default PDF reader and optional callback object: + + cordova.plugins.fileOpener2.open( + '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf + 'application/pdf', + { + error : function(e) { + console.log('Error status: ' + e.status + ' - Error message: ' + e.message); + }, + success : function () { + console.log('file opened successfully'); + } + } + ); + +Notes +------ + +- For properly opening _any_ file, you must already have a suitable reader for that particular file type installed on your device. Otherwise this will not work. + + +- [It is reported](https://github.com/pwlin/cordova-plugin-file-opener2/issues/2#issuecomment-41295793) that in iOS, you might need to remove `` from your `config.xml` + +- If you are wondering what MIME-type should you pass as the second argument to `open` function, [here is a list of all known MIME-types](http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co) + + +Additional Android Functions +----------------------------- +####The following functions are available in Android platform + +###.uninstall(_packageId, callbackContext_) +Uninstall a package with its id. + + cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', { + error : function(e) { + console.log('Error status: ' + e.status + ' - Error message: ' + e.message); + }, + success : function() { + console.log('Uninstall intent activity started.'); + } + }); + +###.appIsInstalled(_packageId, callbackContext_) +Check if an app is already installed. + + cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', { + success : function(res) { + if (res.status === 0) { + console.log('Adobe Reader is not installed.'); + } else { + console.log('Adobe Reader is installed.') + } + } + }); + +LICENSE +-------- +The MIT License (MIT) + +Copyright (c) 2013 pwlin - pwlin05@gmail.com + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/package.json b/package.json index 995c369..43601a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.4", + "version": "2.0.5", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index 861eafb..a993634 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) @@ -27,7 +27,7 @@ From 6294ac8ae34a6a4ce155e5b252626c36724dbff3 Mon Sep 17 00:00:00 2001 From: Frank Fenton Date: Tue, 31 Jan 2017 15:30:24 +1100 Subject: [PATCH 12/76] add android support library to required frameworks --- plugin.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin.xml b/plugin.xml index a993634..fdc17e9 100644 --- a/plugin.xml +++ b/plugin.xml @@ -37,6 +37,7 @@ + From 21e8e0bca0b9d1701311bcdf1a88bf25f42d1306 Mon Sep 17 00:00:00 2001 From: pwlin Date: Tue, 31 Jan 2017 11:31:38 +0100 Subject: [PATCH 13/76] Upped the version to 2.0.6 --- README.md | 4 ++-- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1268333..4fe6cee 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ Contributors ------------ -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/) +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton) A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.5 +Current Version: 2.0.6 ---------------- Requirements diff --git a/package.json b/package.json index 43601a4..3cad882 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.5", + "version": "2.0.6", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index fdc17e9..7483a41 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From c16d332a143832fc73a5047691a60de011a701ca Mon Sep 17 00:00:00 2001 From: pwlin Date: Fri, 3 Feb 2017 09:55:13 +0100 Subject: [PATCH 14/76] Andoid: Fixed a bug in stripFileProtocol function --- .../github/pwlin/cordova/plugins/fileopener2/FileOpener2.java | 2 ++ 1 file changed, 2 insertions(+) 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 b330b4f..66d3f09 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -168,6 +168,8 @@ public class FileOpener2 extends CordovaPlugin { private String stripFileProtocol(String uriString) { if (uriString.startsWith("file://")) { uriString = uriString.substring(7); + } else if (uriString.startsWith("content://")) { + uriString = uriString.substring(10); } return uriString; } From 86c7c92ecfac008fbe2ce5647f2fdd946c622bd9 Mon Sep 17 00:00:00 2001 From: pwlin Date: Fri, 3 Feb 2017 09:56:56 +0100 Subject: [PATCH 15/76] Bumped the version to 2.0.7 --- README.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4fe6cee..fae3e10 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.6 +Current Version: 2.0.7 ---------------- Requirements diff --git a/package.json b/package.json index 3cad882..eca9de5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.6", + "version": "2.0.7", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", From 92f9f1b250e902cd632cec9d6b79ac2d72da6ca0 Mon Sep 17 00:00:00 2001 From: pwlin Date: Fri, 3 Feb 2017 09:58:09 +0100 Subject: [PATCH 16/76] Bumped the version to 2.0.7 --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 7483a41..acb9a6e 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From 1e64de3cd313281fb3447ed758d5802df85ed829 Mon Sep 17 00:00:00 2001 From: Mark Holmes Date: Tue, 21 Feb 2017 15:09:21 -0600 Subject: [PATCH 17/76] Fixes Android 6 file opening failure. --- .../github/pwlin/cordova/plugins/fileopener2/FileOpener2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 66d3f09..fba645f 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -98,7 +98,7 @@ public class FileOpener2 extends CordovaPlugin { try { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); - if(Build.VERSION.SDK_INT >= 24){ + if(Build.VERSION.SDK_INT >= 23){ Context context = cordova.getActivity().getApplicationContext(); path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); From 6482e9c2a43f26f86a4fe47055535f7020be5ee0 Mon Sep 17 00:00:00 2001 From: pwlin Date: Wed, 22 Feb 2017 01:14:54 +0100 Subject: [PATCH 18/76] Bumped the version to 2.0.8 --- README.md | 4 ++-- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fae3e10..b2b12c0 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ Contributors ------------ -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton) +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91) A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.7 +Current Version: 2.0.8 ---------------- Requirements diff --git a/package.json b/package.json index eca9de5..8e4bad5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.7", + "version": "2.0.8", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index acb9a6e..f9b6697 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From 18cc06bad65cb6153eaf485650880ff2f761a891 Mon Sep 17 00:00:00 2001 From: Ophir Stern Date: Mon, 20 Mar 2017 10:11:14 +0200 Subject: [PATCH 19/76] Update opener_paths.xml Solving issue https://github.com/pwlin/cordova-plugin-file-opener2/issues/102 for cached dir. Probably need to do to all other dir.'s as well (persistent, etc....) --- src/android/res/xml/opener_paths.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/android/res/xml/opener_paths.xml b/src/android/res/xml/opener_paths.xml index a6ce6d3..c083eea 100644 --- a/src/android/res/xml/opener_paths.xml +++ b/src/android/res/xml/opener_paths.xml @@ -1,4 +1,5 @@ + From 0be8e277750ee85938bd557a2d5f9afaf683444b Mon Sep 17 00:00:00 2001 From: pwlin Date: Mon, 20 Mar 2017 10:46:06 +0100 Subject: [PATCH 20/76] Bumped the version to 2.0.9 --- README.md | 4 ++-- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b2b12c0..28e29d6 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ Contributors ------------ -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91) +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1) A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.8 +Current Version: 2.0.9 ---------------- Requirements diff --git a/package.json b/package.json index 8e4bad5..982d3dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.8", + "version": "2.0.9", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index f9b6697..6c86421 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From 69099524c57ea00593bbc4014f7890c1b41b83ce Mon Sep 17 00:00:00 2001 From: pwlin Date: Wed, 5 Apr 2017 17:53:35 +0200 Subject: [PATCH 21/76] Added back Gillardo's iOS10 fix in #80 - also see #103 --- README.md | 2 +- package.json | 2 +- plugin.xml | 2 +- src/ios/FileOpener2.m | 6 ++++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 28e29d6..1aadb76 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.9 +Current Version: 2.0.10 ---------------- Requirements diff --git a/package.json b/package.json index 982d3dc..9d7109b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.9", + "version": "2.0.10", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index 6c86421..80acb56 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index b9f67fa..bdb7657 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -43,8 +43,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. dispatch_async(dispatch_get_main_queue(), ^{ // TODO: test if this is a URI or a path - NSURL *fileURL = [NSURL URLWithString:path]; - + // Use one of the following lines + //NSURL *fileURL = [NSURL URLWithString:path]; + NSURL *fileURL = [NSURL fileURLWithPath:path]; + localFile = fileURL.path; NSLog(@"looking for file at %@", fileURL); From de09dc01851161f758b54bf7b7961954e721c8ee Mon Sep 17 00:00:00 2001 From: pwlin Date: Thu, 6 Apr 2017 14:43:10 +0200 Subject: [PATCH 22/76] Added *.bak to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0f182a0..60a0475 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.jar *.war *.ear +*.bak From 9a0c6dfb5cde44d9fe1036f1a54c1434bf3b580d Mon Sep 17 00:00:00 2001 From: pwlin Date: Thu, 6 Apr 2017 14:44:37 +0200 Subject: [PATCH 23/76] Manually merged PR #107 --- src/ios/FileOpener2.h | 1 + src/ios/FileOpener2.m | 96 ++++++++++++++++++++++++------------------- 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/src/ios/FileOpener2.h b/src/ios/FileOpener2.h index 5d9e984..f3014d0 100644 --- a/src/ios/FileOpener2.h +++ b/src/ios/FileOpener2.h @@ -28,6 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. } @property(nonatomic, strong) UIDocumentInteractionController *controller; +@property(nonatomic, strong) CDVViewController *cdvViewController; - (void) open: (CDVInvokedUrlCommand*)command; diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index bdb7657..318e63f 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -27,57 +27,69 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #import @implementation FileOpener2 +@synthesize controller = docController; - (void) open: (CDVInvokedUrlCommand*)command { - NSString *path = command.arguments[0]; - NSString *uti = command.arguments[1]; - if (!uti || (NSNull*)uti == [NSNull null]) { - NSArray *dotParts = [path componentsSeparatedByString:@"."]; - NSString *fileExt = [dotParts lastObject]; - - uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL); - } + NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSString *contentType = nil; - CDVViewController* cont = (CDVViewController*)[ super viewController ]; + if([command.arguments count] == 2) { // Includes contentType + contentType = [command.arguments objectAtIndex:1]; + } - dispatch_async(dispatch_get_main_queue(), ^{ - // TODO: test if this is a URI or a path - // Use one of the following lines - //NSURL *fileURL = [NSURL URLWithString:path]; - NSURL *fileURL = [NSURL fileURLWithPath:path]; + CDVViewController* cont = (CDVViewController*)[super viewController]; + self.cdvViewController = cont; - localFile = fileURL.path; - - NSLog(@"looking for file at %@", fileURL); - NSFileManager *fm = [NSFileManager defaultManager]; - if(![fm fileExistsAtPath:localFile]) { - NSDictionary *jsonObj = @{@"status" : @"9", - @"message" : @"File does not exist"}; - CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR - messageAsDictionary:jsonObj]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - return; - } + NSArray *dotParts = [path componentsSeparatedByString:@"."]; + NSString *fileExt = [dotParts lastObject]; - self.controller = [UIDocumentInteractionController interactionControllerWithURL:fileURL]; - self.controller.delegate = self; - self.controller.UTI = uti; + NSString *uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL); - CGRect rect = CGRectMake(0, 0, 1000.0f, 150.0f); - CDVPluginResult* pluginResult = nil; - BOOL wasOpened = [self.controller presentOptionsMenuFromRect:rect inView:cont.view animated:NO]; + dispatch_async(dispatch_get_main_queue(), ^{ + NSURL *fileURL = [NSURL URLWithString:path]; - if(wasOpened) { - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @""]; - } else { - NSDictionary *jsonObj = @{@"status" : @"9", - @"message" : @"Could not handle UTI"}; - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR - messageAsDictionary:jsonObj]; - } - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }); + localFile = fileURL.path; + + NSLog(@"looking for file at %@", fileURL); + NSFileManager *fm = [NSFileManager defaultManager]; + if(![fm fileExistsAtPath:localFile]) { + NSDictionary *jsonObj = @{@"status" : @"9", + @"message" : @"File does not exist"}; + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + return; + } + + docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL]; + docController.delegate = self; + docController.UTI = uti; + + CDVPluginResult* pluginResult = nil; + + //Opens the file preview + BOOL wasOpened = [docController presentPreviewAnimated: NO]; + + if(wasOpened) { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @""]; + //NSLog(@"Success"); + } else { + NSDictionary *jsonObj = [ [NSDictionary alloc] + initWithObjectsAndKeys : + @"9", @"status", + @"Could not handle UTI", @"message", + nil + ]; + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj]; + } + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }); } @end + +@implementation FileOpener2 (UIDocumentInteractionControllerDelegate) + - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { + return self.cdvViewController; + } +@end From bfbda858b72f0570cc4f7e686af3cc04b11d5913 Mon Sep 17 00:00:00 2001 From: pwlin Date: Thu, 6 Apr 2017 14:54:17 +0200 Subject: [PATCH 24/76] Added new contributors --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1aadb76..bde7d16 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Contributors ------------ -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1) +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov) A File Opener Plugin for Cordova (The Original Version) From 69edd06b1d89d1efd591fcfd5eaca905630f53ce Mon Sep 17 00:00:00 2001 From: pwlin Date: Thu, 6 Apr 2017 14:55:29 +0200 Subject: [PATCH 25/76] Bumped the version to 2.0.11 --- README.md | 2 +- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bde7d16..0c459ef 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.10 +Current Version: 2.0.11 ---------------- Requirements diff --git a/package.json b/package.json index 9d7109b..0423bd9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.10", + "version": "2.0.11", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index 80acb56..06e5747 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From 5b499ea443dc467a0035dc5d700ad7cbc8eff39e Mon Sep 17 00:00:00 2001 From: pwlin Date: Thu, 6 Apr 2017 21:35:42 +0200 Subject: [PATCH 26/76] Add files path to opener_paths.xml --- src/android/res/xml/opener_paths.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/android/res/xml/opener_paths.xml b/src/android/res/xml/opener_paths.xml index c083eea..6a61946 100644 --- a/src/android/res/xml/opener_paths.xml +++ b/src/android/res/xml/opener_paths.xml @@ -1,5 +1,6 @@ + From 4f29b8d29097604304c71b016e90c363aa3edce8 Mon Sep 17 00:00:00 2001 From: pwlin Date: Thu, 6 Apr 2017 21:36:38 +0200 Subject: [PATCH 27/76] Bumped the version to 2.0.12 --- README.md | 2 +- package.json | 2 +- plugin.xml | 17 +++++------------ 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 0c459ef..f6a5461 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.11 +Current Version: 2.0.12 ---------------- Requirements diff --git a/package.json b/package.json index 0423bd9..e5a7e9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.11", + "version": "2.0.12", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index 06e5747..2805c28 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) @@ -26,17 +26,11 @@ - - + + - + @@ -61,8 +55,7 @@ - - + From 73120a73ac931e14d460e642ef2573e4acdd5124 Mon Sep 17 00:00:00 2001 From: pwlin Date: Thu, 6 Apr 2017 23:15:04 +0200 Subject: [PATCH 28/76] Added more paths to opener_paths.xml --- src/android/res/xml/opener_paths.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/android/res/xml/opener_paths.xml b/src/android/res/xml/opener_paths.xml index 6a61946..9dc2098 100644 --- a/src/android/res/xml/opener_paths.xml +++ b/src/android/res/xml/opener_paths.xml @@ -1,6 +1,8 @@ + + From ca739743885654ea6425af9ec34056f31edd4ad4 Mon Sep 17 00:00:00 2001 From: pwlin Date: Thu, 6 Apr 2017 23:16:34 +0200 Subject: [PATCH 29/76] Bumped the version to 2.0.13 --- README.md | 2 +- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f6a5461..9047c56 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.12 +Current Version: 2.0.13 ---------------- Requirements diff --git a/package.json b/package.json index e5a7e9f..a9a3c5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.12", + "version": "2.0.13", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index 2805c28..16ccfe2 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From d316fac5a10af035a9b79d25a2609b3581df2ee2 Mon Sep 17 00:00:00 2001 From: Jeremie Date: Wed, 19 Apr 2017 13:31:16 +0200 Subject: [PATCH 30/76] Fix for APK install on Android 24 Added an exception to handle APKs differently if the android version is 6 --- .../github/pwlin/cordova/plugins/fileopener2/FileOpener2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fba645f..08667aa 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -98,7 +98,7 @@ public class FileOpener2 extends CordovaPlugin { try { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); - if(Build.VERSION.SDK_INT >= 23){ + if(Build.VERSION.SDK_INT >= 23 && !(contentType.equals("application/vnd.android.package-archive") && Build.VERSION.SDK_INT == 24)){ Context context = cordova.getActivity().getApplicationContext(); path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); From ed429e58015b2ff677d219987a8283396c75e028 Mon Sep 17 00:00:00 2001 From: Jeremie Date: Wed, 19 Apr 2017 13:37:44 +0200 Subject: [PATCH 31/76] Update FileOpener2.java --- .../github/pwlin/cordova/plugins/fileopener2/FileOpener2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 08667aa..ad57708 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -98,7 +98,7 @@ public class FileOpener2 extends CordovaPlugin { try { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); - if(Build.VERSION.SDK_INT >= 23 && !(contentType.equals("application/vnd.android.package-archive") && Build.VERSION.SDK_INT == 24)){ + if(Build.VERSION.SDK_INT >= 23 && !(contentType.equals("application/vnd.android.package-archive") && Build.VERSION.SDK_INT == 23)){ Context context = cordova.getActivity().getApplicationContext(); path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); From 5dc3e217e01daf8e55304e79b12d985aed113d7b Mon Sep 17 00:00:00 2001 From: Jeremie Date: Wed, 19 Apr 2017 13:39:50 +0200 Subject: [PATCH 32/76] Update FileOpener2.java --- .../github/pwlin/cordova/plugins/fileopener2/FileOpener2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ad57708..a85a87b 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -98,7 +98,7 @@ public class FileOpener2 extends CordovaPlugin { try { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); - if(Build.VERSION.SDK_INT >= 23 && !(contentType.equals("application/vnd.android.package-archive") && Build.VERSION.SDK_INT == 23)){ + if(Build.VERSION.SDK_INT >= 23 && !(contentType.equals("application/vnd.android.package-archive"))){ Context context = cordova.getActivity().getApplicationContext(); path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); From 06671fbdcebc9730ab333cc76e61660f5064005a Mon Sep 17 00:00:00 2001 From: Jeremie Date: Wed, 19 Apr 2017 13:56:54 +0200 Subject: [PATCH 33/76] Update FileOpener2.java --- .../github/pwlin/cordova/plugins/fileopener2/FileOpener2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a85a87b..ad57708 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -98,7 +98,7 @@ public class FileOpener2 extends CordovaPlugin { try { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); - if(Build.VERSION.SDK_INT >= 23 && !(contentType.equals("application/vnd.android.package-archive"))){ + if(Build.VERSION.SDK_INT >= 23 && !(contentType.equals("application/vnd.android.package-archive") && Build.VERSION.SDK_INT == 23)){ Context context = cordova.getActivity().getApplicationContext(); path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); From 8a553db96cfdde8eb9a42b05413a7014374ef779 Mon Sep 17 00:00:00 2001 From: Jeremie Date: Wed, 19 Apr 2017 14:14:47 +0200 Subject: [PATCH 34/76] Update FileOpener2.java --- .../github/pwlin/cordova/plugins/fileopener2/FileOpener2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ad57708..a85a87b 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -98,7 +98,7 @@ public class FileOpener2 extends CordovaPlugin { try { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); - if(Build.VERSION.SDK_INT >= 23 && !(contentType.equals("application/vnd.android.package-archive") && Build.VERSION.SDK_INT == 23)){ + if(Build.VERSION.SDK_INT >= 23 && !(contentType.equals("application/vnd.android.package-archive"))){ Context context = cordova.getActivity().getApplicationContext(); path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); From 8be87033989a1c04861011f36ff6e9d6b39ac00c Mon Sep 17 00:00:00 2001 From: Jeremie Date: Wed, 19 Apr 2017 14:28:51 +0200 Subject: [PATCH 35/76] Removed unused parentheses --- .../github/pwlin/cordova/plugins/fileopener2/FileOpener2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a85a87b..61908c7 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -98,7 +98,7 @@ public class FileOpener2 extends CordovaPlugin { try { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); - if(Build.VERSION.SDK_INT >= 23 && !(contentType.equals("application/vnd.android.package-archive"))){ + if(Build.VERSION.SDK_INT >= 23 && !contentType.equals("application/vnd.android.package-archive")){ Context context = cordova.getActivity().getApplicationContext(); path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); From bc40c0a879431f5625af16fca13f93a64f2e2f9f Mon Sep 17 00:00:00 2001 From: pwlin Date: Wed, 19 Apr 2017 14:38:35 +0200 Subject: [PATCH 36/76] Bumped the version to 2.0.14 --- README.md | 4 ++-- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9047c56..4384cf5 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ Contributors ------------ -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov) +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov), [@lp1bp](https://github.com/lp1bp) A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.13 +Current Version: 2.0.14 ---------------- Requirements diff --git a/package.json b/package.json index a9a3c5e..5794b5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.13", + "version": "2.0.14", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index 16ccfe2..c054e51 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From bbeb4a1227360f07942efe14966aa832bd326093 Mon Sep 17 00:00:00 2001 From: Sergii Stotskyi Date: Thu, 20 Apr 2017 18:36:43 +0300 Subject: [PATCH 37/76] feat(ios): adds method for opening openWith dialog on iOS --- src/ios/FileOpener2.m | 15 ++++++++++++++- www/plugins.FileOpener2.js | 7 ++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 318e63f..6f238e4 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -33,11 +33,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString *contentType = nil; + BOOL showPreview = YES; if([command.arguments count] == 2) { // Includes contentType contentType = [command.arguments objectAtIndex:1]; } + if ([command.arguments count] == 3) { + showPreview = [[command.arguments objectAtIndex:2] boolValue]; + } + CDVViewController* cont = (CDVViewController*)[super viewController]; self.cdvViewController = cont; @@ -68,7 +73,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. CDVPluginResult* pluginResult = nil; //Opens the file preview - BOOL wasOpened = [docController presentPreviewAnimated: NO]; + BOOL wasOpened = NO; + + if (showPreview) { + wasOpened = [docController presentPreviewAnimated: NO]; + } else { + CDVViewController* cont = self.cdvViewController; + CGRect rect = CGRectMake(0, 0, cont.view.bounds.size.width, cont.view.bounds.size.height); + wasOpened = [docController presentOpenInMenuFromRect:rect inView:cont.view animated:YES]; + } if(wasOpened) { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @""]; diff --git a/www/plugins.FileOpener2.js b/www/plugins.FileOpener2.js index 06519dd..c5face4 100644 --- a/www/plugins.FileOpener2.js +++ b/www/plugins.FileOpener2.js @@ -31,6 +31,11 @@ FileOpener2.prototype.open = function (fileName, contentType, callbackContext) { exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType]); }; +FileOpener2.prototype.showOpenWithDialog = function (fileName, contentType, callbackContext) { + callbackContext = callbackContext || {}; + exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, false]); +}; + FileOpener2.prototype.uninstall = function (packageId, callbackContext) { callbackContext = callbackContext || {}; exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'uninstall', [packageId]); @@ -41,4 +46,4 @@ FileOpener2.prototype.appIsInstalled = function (packageId, callbackContext) { exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'appIsInstalled', [packageId]); }; -module.exports = new FileOpener2(); \ No newline at end of file +module.exports = new FileOpener2(); From d08f767a4c87ef53c05e4bd3b6f761332d6785ab Mon Sep 17 00:00:00 2001 From: pwlin Date: Thu, 20 Apr 2017 21:44:42 +0200 Subject: [PATCH 38/76] Update README.md --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4384cf5..494df24 100644 --- a/README.md +++ b/README.md @@ -64,12 +64,23 @@ Notes - If you are wondering what MIME-type should you pass as the second argument to `open` function, [here is a list of all known MIME-types](http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co) +Additional iOS Functions +----------------------------- +The following functions are available in iOS platform +--- + +showOpenWithDialog(fileName, contentType, callbackContext) +--- +Same as `open` function, but this will show openWith dialog on iOS for sending files into another apps. + Additional Android Functions ----------------------------- -####The following functions are available in Android platform +The following functions are available in Android platform +--- -###.uninstall(_packageId, callbackContext_) +.uninstall(_packageId, callbackContext_) +--- Uninstall a package with its id. cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', { @@ -81,7 +92,8 @@ Uninstall a package with its id. } }); -###.appIsInstalled(_packageId, callbackContext_) +.appIsInstalled(_packageId, callbackContext_) +--- Check if an app is already installed. cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', { From 46f83d72af34f39655474ad3aa202ae008753b33 Mon Sep 17 00:00:00 2001 From: pwlin Date: Thu, 20 Apr 2017 21:49:58 +0200 Subject: [PATCH 39/76] Update README.md --- README.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 494df24..911f0f2 100644 --- a/README.md +++ b/README.md @@ -65,22 +65,21 @@ Notes - If you are wondering what MIME-type should you pass as the second argument to `open` function, [here is a list of all known MIME-types](http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co) Additional iOS Functions ------------------------------ -The following functions are available in iOS platform --- +The following functions are available in iOS platform: + +`.showOpenWithDialog(fileName, contentType, callbackContext)` -showOpenWithDialog(fileName, contentType, callbackContext) ---- Same as `open` function, but this will show openWith dialog on iOS for sending files into another apps. +--- Additional Android Functions ------------------------------ -The following functions are available in Android platform --- +The following functions are available in Android platform: + +`.uninstall(packageId, callbackContext)` -.uninstall(_packageId, callbackContext_) ---- Uninstall a package with its id. cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', { @@ -92,8 +91,10 @@ Uninstall a package with its id. } }); -.appIsInstalled(_packageId, callbackContext_) --- + +`.appIsInstalled(packageId, callbackContext)` + Check if an app is already installed. cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', { @@ -106,6 +107,8 @@ Check if an app is already installed. } }); +--- + LICENSE -------- The MIT License (MIT) From c25c8967321a6962e6ceb75692a0e19a6cae3e39 Mon Sep 17 00:00:00 2001 From: pwlin Date: Thu, 20 Apr 2017 21:53:14 +0200 Subject: [PATCH 40/76] Update README.md --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 911f0f2..8ec424b 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ Additional iOS Functions The following functions are available in iOS platform: `.showOpenWithDialog(fileName, contentType, callbackContext)` - +--- Same as `open` function, but this will show openWith dialog on iOS for sending files into another apps. --- @@ -79,7 +79,7 @@ Additional Android Functions The following functions are available in Android platform: `.uninstall(packageId, callbackContext)` - +--- Uninstall a package with its id. cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', { @@ -91,10 +91,8 @@ Uninstall a package with its id. } }); ---- - `.appIsInstalled(packageId, callbackContext)` - +--- Check if an app is already installed. cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', { From a3308464b282aec8cd6352701ad6c99334329954 Mon Sep 17 00:00:00 2001 From: pwlin Date: Thu, 20 Apr 2017 21:55:25 +0200 Subject: [PATCH 41/76] Bumped the version to 2.0.15 --- README.md | 4 ++-- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8ec424b..239d8b7 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ Contributors ------------ -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov), [@lp1bp](https://github.com/lp1bp) +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov), [@lp1bp](https://github.com/lp1bp), [@stalniy](https://github.com/stalniy) A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.14 +Current Version: 2.0.15 ---------------- Requirements diff --git a/package.json b/package.json index 5794b5f..eff9076 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.14", + "version": "2.0.15", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index c054e51..1296b6b 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From 3bb04832461acf98048dcc4f7650339cbce674ae Mon Sep 17 00:00:00 2001 From: pwlin Date: Wed, 24 May 2017 11:43:14 +0200 Subject: [PATCH 42/76] Fixes #128 --- .../github/pwlin/cordova/plugins/fileopener2/FileOpener2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 61908c7..d0e6994 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -98,7 +98,7 @@ public class FileOpener2 extends CordovaPlugin { try { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); - if(Build.VERSION.SDK_INT >= 23 && !contentType.equals("application/vnd.android.package-archive")){ + if((Build.VERSION.SDK_INT >= 23 && !contentType.equals("application/vnd.android.package-archive")) || (Build.VERSION.SDK_INT == 24 && contentType.equals("application/vnd.android.package-archive"))) { Context context = cordova.getActivity().getApplicationContext(); path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); From b7b12bdcf3549361879711386551b2469aa2ad03 Mon Sep 17 00:00:00 2001 From: pwlin Date: Wed, 24 May 2017 11:46:34 +0200 Subject: [PATCH 43/76] Bumped the version to 2.0.16 --- README.md | 4 ++-- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 239d8b7..64f12b4 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ Contributors ------------ -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov), [@lp1bp](https://github.com/lp1bp), [@stalniy](https://github.com/stalniy) +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov), [@lp1bp](https://github.com/lp1bp), [@stalniy](https://github.com/stalniy), [@liugogal](https://github.com/liugogal) A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.15 +Current Version: 2.0.16 ---------------- Requirements diff --git a/package.json b/package.json index eff9076..982e1ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.15", + "version": "2.0.16", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index 1296b6b..51005aa 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From bc350a47fdea8fcbc08945cacf3ec775d7f4cbc4 Mon Sep 17 00:00:00 2001 From: Luca Caprini Date: Mon, 29 May 2017 16:02:56 +0200 Subject: [PATCH 44/76] showOpenWithDialog on Android --- .../plugins/fileopener2/FileOpener2.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 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 d0e6994..f5c7cb3 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -58,7 +58,10 @@ public class FileOpener2 extends CordovaPlugin { */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("open")) { - this._open(args.getString(0), args.getString(1), callbackContext); + String fileUrl = args.getString(0); + String contentType = args.getString(1); + Boolean openWith = (args.length() > 2) && args.getBoolean(2); + this._open(fileUrl, contentType, openWith, callbackContext); } else if (action.equals("uninstall")) { this._uninstall(args.getString(0), callbackContext); @@ -84,7 +87,7 @@ public class FileOpener2 extends CordovaPlugin { return true; } - private void _open(String fileArg, String contentType, CallbackContext callbackContext) throws JSONException { + private void _open(String fileArg, String contentType, Boolean openWith, CallbackContext callbackContext) throws JSONException { String fileName = ""; try { CordovaResourceApi resourceApi = webView.getResourceApi(); @@ -98,7 +101,7 @@ public class FileOpener2 extends CordovaPlugin { try { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); - if((Build.VERSION.SDK_INT >= 23 && !contentType.equals("application/vnd.android.package-archive")) || (Build.VERSION.SDK_INT == 24 && contentType.equals("application/vnd.android.package-archive"))) { + if(Build.VERSION.SDK_INT >= 23 && !contentType.equals("application/vnd.android.package-archive")){ Context context = cordova.getActivity().getApplicationContext(); path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); @@ -121,8 +124,13 @@ public class FileOpener2 extends CordovaPlugin { * @see * http://stackoverflow.com/questions/14321376/open-an-activity-from-a-cordovaplugin */ - cordova.getActivity().startActivity(intent); - //cordova.getActivity().startActivity(Intent.createChooser(intent,"Open File in...")); + if(openWith){ + cordova.getActivity().startActivity(Intent.createChooser(intent,"Open File in...")); + } + else{ + cordova.getActivity().startActivity(intent); + } + callbackContext.success(); } catch (android.content.ActivityNotFoundException e) { JSONObject errorObj = new JSONObject(); From 6b34b93af48175924bcf5ca1ad30cbc4c59cd043 Mon Sep 17 00:00:00 2001 From: Luca Caprini Date: Mon, 29 May 2017 16:06:16 +0200 Subject: [PATCH 45/76] showOpenWithDialog on Android --- README.md | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 64f12b4..59e3618 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,21 @@ Open a PDF document with the default PDF reader and optional callback object: } ); +Open a system modal to open PDF document with one of the already installed app and optional callback object: + + cordova.plugins.fileOpener2.showOpenWithDialog( + '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf + 'application/pdf', + { + error : function(e) { + console.log('Error status: ' + e.status + ' - Error message: ' + e.message); + }, + success : function () { + console.log('file opened successfully'); + } + } + ); + Notes ------ @@ -64,16 +79,6 @@ Notes - If you are wondering what MIME-type should you pass as the second argument to `open` function, [here is a list of all known MIME-types](http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co) -Additional iOS Functions ---- -The following functions are available in iOS platform: - -`.showOpenWithDialog(fileName, contentType, callbackContext)` ---- -Same as `open` function, but this will show openWith dialog on iOS for sending files into another apps. - ---- - Additional Android Functions --- The following functions are available in Android platform: From d64904062925fbd3f7b885427ecbb764b4ce7d7c Mon Sep 17 00:00:00 2001 From: Luca Caprini Date: Mon, 29 May 2017 16:36:01 +0200 Subject: [PATCH 46/76] FIX showOpenWithDialog on Android --- .../cordova/plugins/fileopener2/FileOpener2.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 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 f5c7cb3..c74b6ce 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -60,8 +60,11 @@ public class FileOpener2 extends CordovaPlugin { if (action.equals("open")) { String fileUrl = args.getString(0); String contentType = args.getString(1); - Boolean openWith = (args.length() > 2) && args.getBoolean(2); - this._open(fileUrl, contentType, openWith, callbackContext); + Boolean openWithDefault = true; + if(args.length() > 2){ + openWithDefault = args.getBoolean(2); + } + this._open(fileUrl, contentType, openWithDefault, callbackContext); } else if (action.equals("uninstall")) { this._uninstall(args.getString(0), callbackContext); @@ -87,7 +90,7 @@ public class FileOpener2 extends CordovaPlugin { return true; } - private void _open(String fileArg, String contentType, Boolean openWith, CallbackContext callbackContext) throws JSONException { + private void _open(String fileArg, String contentType, Boolean openWithDefault, CallbackContext callbackContext) throws JSONException { String fileName = ""; try { CordovaResourceApi resourceApi = webView.getResourceApi(); @@ -124,11 +127,11 @@ public class FileOpener2 extends CordovaPlugin { * @see * http://stackoverflow.com/questions/14321376/open-an-activity-from-a-cordovaplugin */ - if(openWith){ - cordova.getActivity().startActivity(Intent.createChooser(intent,"Open File in...")); + if(openWithDefault){ + cordova.getActivity().startActivity(intent); } else{ - cordova.getActivity().startActivity(intent); + cordova.getActivity().startActivity(Intent.createChooser(intent, "Open File in...")); } callbackContext.success(); From f99d47fce9635af93eb90f2dea97fc2dc9fc831e Mon Sep 17 00:00:00 2001 From: pwlin Date: Tue, 30 May 2017 12:23:38 +0200 Subject: [PATCH 47/76] readded check for opening apk files with SDK 24 --- .../github/pwlin/cordova/plugins/fileopener2/FileOpener2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c74b6ce..cee6002 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -104,7 +104,7 @@ public class FileOpener2 extends CordovaPlugin { try { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); - if(Build.VERSION.SDK_INT >= 23 && !contentType.equals("application/vnd.android.package-archive")){ + if((Build.VERSION.SDK_INT >= 23 && !contentType.equals("application/vnd.android.package-archive")) || (Build.VERSION.SDK_INT == 24 && contentType.equals("application/vnd.android.package-archive"))) { Context context = cordova.getActivity().getApplicationContext(); path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); From 4fc32155da7f8539a7f492b20b4419c994c97349 Mon Sep 17 00:00:00 2001 From: pwlin Date: Tue, 30 May 2017 12:28:55 +0200 Subject: [PATCH 48/76] Bumped the vertion to 2.0.17 --- README.md | 4 ++-- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 59e3618..b660e8f 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ Contributors ------------ -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov), [@lp1bp](https://github.com/lp1bp), [@stalniy](https://github.com/stalniy), [@liugogal](https://github.com/liugogal) +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov), [@lp1bp](https://github.com/lp1bp), [@stalniy](https://github.com/stalniy), [@liugogal](https://github.com/liugogal), [@lcaprini](https://github.com/lcaprini) A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.16 +Current Version: 2.0.17 ---------------- Requirements diff --git a/package.json b/package.json index 982e1ce..22aaafe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.16", + "version": "2.0.17", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index 51005aa..460a0ef 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From 64795f52c4f25b2a27ad157f1595ee0d1379b2cd Mon Sep 17 00:00:00 2001 From: jcdickman Date: Thu, 1 Jun 2017 09:17:25 -0500 Subject: [PATCH 49/76] ${applicationId} authority --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 460a0ef..878ad12 100644 --- a/plugin.xml +++ b/plugin.xml @@ -26,7 +26,7 @@ - + From 764f5aed028c2379ed720b7badeb53a2dc12cf3b Mon Sep 17 00:00:00 2001 From: pwlin Date: Thu, 1 Jun 2017 22:45:27 +0200 Subject: [PATCH 50/76] Bumped the version to 2.0.18 --- README.md | 4 ++-- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b660e8f..830c3cf 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ Contributors ------------ -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov), [@lp1bp](https://github.com/lp1bp), [@stalniy](https://github.com/stalniy), [@liugogal](https://github.com/liugogal), [@lcaprini](https://github.com/lcaprini) +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov), [@lp1bp](https://github.com/lp1bp), [@stalniy](https://github.com/stalniy), [@liugogal](https://github.com/liugogal), [@lcaprini](https://github.com/lcaprini), [@jcdickman](https://github.com/jcdickman) A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.17 +Current Version: 2.0.18 ---------------- Requirements diff --git a/package.json b/package.json index 22aaafe..af6b516 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.17", + "version": "2.0.18", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index 878ad12..40da268 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From 639f1c46c43461db5f7332324f1cea6635e92d69 Mon Sep 17 00:00:00 2001 From: pwlin Date: Fri, 2 Jun 2017 09:01:54 +0200 Subject: [PATCH 51/76] Fixed a problem when opening APK files with Android SDK 25 --- .../github/pwlin/cordova/plugins/fileopener2/FileOpener2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cee6002..541d5e4 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -104,7 +104,7 @@ public class FileOpener2 extends CordovaPlugin { try { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); - if((Build.VERSION.SDK_INT >= 23 && !contentType.equals("application/vnd.android.package-archive")) || (Build.VERSION.SDK_INT == 24 && contentType.equals("application/vnd.android.package-archive"))) { + if((Build.VERSION.SDK_INT >= 23 && !contentType.equals("application/vnd.android.package-archive")) || ((Build.VERSION.SDK_INT == 24 || Build.VERSION.SDK_INT == 25) && contentType.equals("application/vnd.android.package-archive"))) { Context context = cordova.getActivity().getApplicationContext(); path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); From f08a0fb15495e95f2bbe1fdb65077bd6e036b955 Mon Sep 17 00:00:00 2001 From: pwlin Date: Fri, 2 Jun 2017 09:03:11 +0200 Subject: [PATCH 52/76] Bumped the version to 2.0.19 --- README.md | 2 +- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 830c3cf..63b1cf0 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.18 +Current Version: 2.0.19 ---------------- Requirements diff --git a/package.json b/package.json index af6b516..436e935 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.18", + "version": "2.0.19", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", diff --git a/plugin.xml b/plugin.xml index 40da268..2ec207e 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From 34bf878d97019cb4924f99e63a32e4c136449609 Mon Sep 17 00:00:00 2001 From: X-Net Mac Date: Thu, 13 Jul 2017 19:13:43 +0200 Subject: [PATCH 53/76] option to force usage of contentType on ios --- src/ios/FileOpener2.m | 20 +++++++++++++++----- www/plugins.FileOpener2.js | 6 ++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 6f238e4..4cc8cd0 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -34,22 +34,32 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString *contentType = nil; BOOL showPreview = YES; + BOOL useContentType = NO; - if([command.arguments count] == 2) { // Includes contentType + if([command.arguments count] >= 2) { // Includes contentType contentType = [command.arguments objectAtIndex:1]; } - if ([command.arguments count] == 3) { + if ([command.arguments count] >= 3) { showPreview = [[command.arguments objectAtIndex:2] boolValue]; } + if ([command.arguments count] >= 4) { + useContentType = [[command.arguments objectAtIndex:3] boolValue]; + } + CDVViewController* cont = (CDVViewController*)[super viewController]; self.cdvViewController = cont; + NSString *uti = nil; - NSArray *dotParts = [path componentsSeparatedByString:@"."]; - NSString *fileExt = [dotParts lastObject]; + if(useContentType){ + uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)contentType, NULL); + } else { + NSArray *dotParts = [path componentsSeparatedByString:@"."]; + NSString *fileExt = [dotParts lastObject]; - NSString *uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL); + uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL); + } dispatch_async(dispatch_get_main_queue(), ^{ NSURL *fileURL = [NSURL URLWithString:path]; diff --git a/www/plugins.FileOpener2.js b/www/plugins.FileOpener2.js index c5face4..eb75211 100644 --- a/www/plugins.FileOpener2.js +++ b/www/plugins.FileOpener2.js @@ -36,6 +36,12 @@ FileOpener2.prototype.showOpenWithDialog = function (fileName, contentType, call exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, false]); }; +FileOpener2.prototype.openWithContentType = function (fileName, contentType, callbackContext) { + callbackContext = callbackContext || {}; + if(typeof contentType !== "string"){ throw new Error("contentType must be a String") } + exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, true, true]); +}; + FileOpener2.prototype.uninstall = function (packageId, callbackContext) { callbackContext = callbackContext || {}; exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'uninstall', [packageId]); From 7be0278c17a830c83cd73b3270e2a1aca3ed4350 Mon Sep 17 00:00:00 2001 From: pwlin Date: Mon, 24 Jul 2017 15:00:05 +0200 Subject: [PATCH 54/76] Setting contentType to an empty string if it is undefined --- www/plugins.FileOpener2.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/www/plugins.FileOpener2.js b/www/plugins.FileOpener2.js index c5face4..ebe9313 100644 --- a/www/plugins.FileOpener2.js +++ b/www/plugins.FileOpener2.js @@ -27,11 +27,13 @@ var exec = require('cordova/exec'); function FileOpener2() {} FileOpener2.prototype.open = function (fileName, contentType, callbackContext) { + contentType = contentType || ''; callbackContext = callbackContext || {}; exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType]); }; FileOpener2.prototype.showOpenWithDialog = function (fileName, contentType, callbackContext) { + contentType = contentType || ''; callbackContext = callbackContext || {}; exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, false]); }; From 538cd1305fc3341eb7761b174eeba451cd3ca350 Mon Sep 17 00:00:00 2001 From: X-Net Mac Date: Tue, 25 Jul 2017 08:53:34 +0200 Subject: [PATCH 55/76] iOS: use mimetype if provided, otherwise fall back to file extension --- src/ios/FileOpener2.m | 19 +++++-------------- www/plugins.FileOpener2.js | 6 ------ 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 4cc8cd0..257a356 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -31,34 +31,25 @@ 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 *contentType = nil; + NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSString *contentType = [command.arguments objectAtIndex:1]; BOOL showPreview = YES; - BOOL useContentType = NO; - - if([command.arguments count] >= 2) { // Includes contentType - contentType = [command.arguments objectAtIndex:1]; - } if ([command.arguments count] >= 3) { showPreview = [[command.arguments objectAtIndex:2] boolValue]; } - if ([command.arguments count] >= 4) { - useContentType = [[command.arguments objectAtIndex:3] boolValue]; - } - CDVViewController* cont = (CDVViewController*)[super viewController]; self.cdvViewController = cont; NSString *uti = nil; - if(useContentType){ - uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)contentType, NULL); - } else { + if([contentType length] == 0){ NSArray *dotParts = [path componentsSeparatedByString:@"."]; NSString *fileExt = [dotParts lastObject]; uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL); + } else { + uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)contentType, NULL); } dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/www/plugins.FileOpener2.js b/www/plugins.FileOpener2.js index bac1a50..ebe9313 100644 --- a/www/plugins.FileOpener2.js +++ b/www/plugins.FileOpener2.js @@ -38,12 +38,6 @@ FileOpener2.prototype.showOpenWithDialog = function (fileName, contentType, call exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, false]); }; -FileOpener2.prototype.openWithContentType = function (fileName, contentType, callbackContext) { - callbackContext = callbackContext || {}; - if(typeof contentType !== "string"){ throw new Error("contentType must be a String") } - exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, true, true]); -}; - FileOpener2.prototype.uninstall = function (packageId, callbackContext) { callbackContext = callbackContext || {}; exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'uninstall', [packageId]); From ba3cb010c25ac6866c675c2ab70944215b4b9c1e Mon Sep 17 00:00:00 2001 From: imgx64 Date: Wed, 18 Oct 2017 12:29:49 +0300 Subject: [PATCH 56/76] Correctly call Intent.setFlags() --- .../github/pwlin/cordova/plugins/fileopener2/FileOpener2.java | 3 +-- 1 file changed, 1 insertion(+), 2 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 541d5e4..3dec792 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -109,8 +109,7 @@ public class FileOpener2 extends CordovaPlugin { Context context = cordova.getActivity().getApplicationContext(); path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); intent.setDataAndType(path, contentType); - intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); + intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY); //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); List infoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); From ade1872a5c09c1315c8e0ecd0be64b442d0081c3 Mon Sep 17 00:00:00 2001 From: imgx64 Date: Sun, 22 Oct 2017 11:17:29 +0300 Subject: [PATCH 57/76] Fix and document opener_paths.xml --- src/android/res/xml/opener_paths.xml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/android/res/xml/opener_paths.xml b/src/android/res/xml/opener_paths.xml index 9dc2098..0ffc88e 100644 --- a/src/android/res/xml/opener_paths.xml +++ b/src/android/res/xml/opener_paths.xml @@ -1,8 +1,14 @@ + + - - - - + + + + + + + + From 8dd6ca756c4a484b486cfdf7a85e5f2d3bdad70a Mon Sep 17 00:00:00 2001 From: imgx64 Date: Sun, 22 Oct 2017 11:35:47 +0300 Subject: [PATCH 58/76] Remove unnecessary context.grantUriPermission() --- .../pwlin/cordova/plugins/fileopener2/FileOpener2.java | 6 ------ 1 file changed, 6 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 3dec792..b7b6fdd 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -111,12 +111,6 @@ public class FileOpener2 extends CordovaPlugin { intent.setDataAndType(path, contentType); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY); //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - - List infoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); - for (ResolveInfo resolveInfo : infoList) { - String packageName = resolveInfo.activityInfo.packageName; - context.grantUriPermission(packageName, path, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); - } } else { intent.setDataAndType(path, contentType); From 0922f8c16edf2ef4b582315a257993d5768fefed Mon Sep 17 00:00:00 2001 From: imgx64 Date: Sun, 22 Oct 2017 11:50:23 +0300 Subject: [PATCH 59/76] Always use FileProvider --- .../plugins/fileopener2/FileOpener2.java | 17 +++++------------ 1 file changed, 5 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 b7b6fdd..f77f055 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -102,20 +102,13 @@ public class FileOpener2 extends CordovaPlugin { File file = new File(fileName); if (file.exists()) { try { - Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); - if((Build.VERSION.SDK_INT >= 23 && !contentType.equals("application/vnd.android.package-archive")) || ((Build.VERSION.SDK_INT == 24 || Build.VERSION.SDK_INT == 25) && contentType.equals("application/vnd.android.package-archive"))) { - Context context = cordova.getActivity().getApplicationContext(); - path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); - intent.setDataAndType(path, contentType); - intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY); - //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - } - else { - intent.setDataAndType(path, contentType); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - } + Context context = cordova.getActivity().getApplicationContext(); + Uri path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); + intent.setDataAndType(path, contentType); + intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY); + /* * @see * http://stackoverflow.com/questions/14321376/open-an-activity-from-a-cordovaplugin From 6e29bebc1864c826740a752376e71bb47c47e91d Mon Sep 17 00:00:00 2001 From: imgx64 Date: Sun, 22 Oct 2017 13:09:07 +0300 Subject: [PATCH 60/76] Fix opening APK files --- .../plugins/fileopener2/FileOpener2.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 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 f77f055..d4b2fff 100644 --- a/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java +++ b/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java @@ -102,12 +102,28 @@ public class FileOpener2 extends CordovaPlugin { File file = new File(fileName); if (file.exists()) { try { - Intent intent = new Intent(Intent.ACTION_VIEW); + Intent intent; + if (contentType.equals("application/vnd.android.package-archive")) { + // https://stackoverflow.com/questions/9637629/can-we-install-an-apk-from-a-contentprovider/9672282#9672282 + intent = new Intent(Intent.ACTION_INSTALL_PACKAGE); + Uri path; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { + path = Uri.fromFile(file); + } else { + Context context = cordova.getActivity().getApplicationContext(); + path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); + } + intent.setDataAndType(path, contentType); + intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - Context context = cordova.getActivity().getApplicationContext(); - Uri path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); - intent.setDataAndType(path, contentType); - intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY); + } else { + intent = new Intent(Intent.ACTION_VIEW); + Context context = cordova.getActivity().getApplicationContext(); + Uri path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file); + intent.setDataAndType(path, contentType); + intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY); + + } /* * @see From ef84dfbcfda593305f7c126252c94283510824ff Mon Sep 17 00:00:00 2001 From: imgx64 Date: Mon, 23 Oct 2017 08:47:38 +0300 Subject: [PATCH 61/76] Add Android APK installation limitation to README --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 63b1cf0..91e689f 100644 --- a/README.md +++ b/README.md @@ -74,11 +74,24 @@ Notes - For properly opening _any_ file, you must already have a suitable reader for that particular file type installed on your device. Otherwise this will not work. - - [It is reported](https://github.com/pwlin/cordova-plugin-file-opener2/issues/2#issuecomment-41295793) that in iOS, you might need to remove `` from your `config.xml` - If you are wondering what MIME-type should you pass as the second argument to `open` function, [here is a list of all known MIME-types](http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co) +Android APK installation limitation +--- +The following limitations apply when opening an APK file for installation: +- On Android 8+, your application must have the `ACTION_INSTALL_PACKAGE` permission. You can add it by adding this to your app's `config.xml` file: +``` + + + + + +``` + +- Before Android 7, you can only install APKs from the "external" partition. For example, you can install from `cordova.file.externalDataDirectory`, but **not** from `cordova.file.dataDirectory`. Android 7+ does not have this limitation. + Additional Android Functions --- The following functions are available in Android platform: From dfab028e034026f299585b53bcc5970a22b033e1 Mon Sep 17 00:00:00 2001 From: imgx64 Date: Mon, 23 Oct 2017 09:05:49 +0300 Subject: [PATCH 62/76] Fix Android permission instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 91e689f..0f64971 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ The following limitations apply when opening an APK file for installation: - On Android 8+, your application must have the `ACTION_INSTALL_PACKAGE` permission. You can add it by adding this to your app's `config.xml` file: ``` - + From 3511dac4b11f968bb10e767f7ab780c4a69a8a7d Mon Sep 17 00:00:00 2001 From: Aaron Faber Date: Wed, 15 Nov 2017 15:31:54 +0000 Subject: [PATCH 63/76] Added fix to stop support version pulling in alphas --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 2ec207e..daf495b 100644 --- a/plugin.xml +++ b/plugin.xml @@ -31,7 +31,7 @@ - + From 90b620b9218390c59711c15c66f9bf60cd2c729e Mon Sep 17 00:00:00 2001 From: Aaron Faber Date: Mon, 12 Nov 2018 15:14:33 +0000 Subject: [PATCH 64/76] updated android support library version --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index daf495b..0c78ef2 100644 --- a/plugin.xml +++ b/plugin.xml @@ -31,7 +31,7 @@ - + From 054d7fa21b8fcca1f1f5fcdd7374741e0818918e Mon Sep 17 00:00:00 2001 From: Aaron Faber Date: Tue, 13 Nov 2018 10:55:11 +0000 Subject: [PATCH 65/76] allowed support library version to be configurable --- plugin.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 0c78ef2..38885f7 100644 --- a/plugin.xml +++ b/plugin.xml @@ -31,7 +31,8 @@ - + + From 636bce54bcd924fe31bac7213b2ff6c2310b72fc Mon Sep 17 00:00:00 2001 From: Aaron Faber Date: Mon, 10 Dec 2018 16:19:54 +0000 Subject: [PATCH 66/76] chore(): updated readme file with new android_support_version variable --- README.md | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 0f64971..b2431da 100644 --- a/README.md +++ b/README.md @@ -17,17 +17,18 @@ Requirements Installation ------------- - cordova plugin add cordova-plugin-file-opener2 - + $ cordova plugin add cordova-plugin-file-opener2 + $ cordova plugin add cordova-plugin-file-opener2 --variable ANDROID_SUPPORT_VERSION={required version} + Usage ------ cordova.plugins.fileOpener2.open( - filePath, - fileMIMEType, + filePath, + fileMIMEType, { - error : function(){ }, - success : function(){ } - } + error : function(){ }, + success : function(){ } + } ); Examples @@ -35,21 +36,21 @@ Examples Open an APK install dialog: cordova.plugins.fileOpener2.open( - '/sdcard/Download/gmail.apk', + '/sdcard/Download/gmail.apk', 'application/vnd.android.package-archive' ); - + Open a PDF document with the default PDF reader and optional callback object: cordova.plugins.fileOpener2.open( '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf - 'application/pdf', - { - error : function(e) { + 'application/pdf', + { + error : function(e) { console.log('Error status: ' + e.status + ' - Error message: ' + e.message); }, success : function () { - console.log('file opened successfully'); + console.log('file opened successfully'); } } ); @@ -58,13 +59,13 @@ Open a system modal to open PDF document with one of the already installed app a cordova.plugins.fileOpener2.showOpenWithDialog( '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf - 'application/pdf', - { - error : function(e) { + 'application/pdf', + { + error : function(e) { console.log('Error status: ' + e.status + ' - Error message: ' + e.message); }, success : function () { - console.log('file opened successfully'); + console.log('file opened successfully'); } } ); @@ -102,7 +103,7 @@ Uninstall a package with its id. cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', { error : function(e) { - console.log('Error status: ' + e.status + ' - Error message: ' + e.message); + console.log('Error status: ' + e.status + ' - Error message: ' + e.message); }, success : function() { console.log('Uninstall intent activity started.'); From c3e972cab4260a72f3be2fa76d27e9f999da0e88 Mon Sep 17 00:00:00 2001 From: shnist Date: Mon, 10 Dec 2018 16:37:06 +0000 Subject: [PATCH 67/76] chore(): updated collaborators on readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b2431da..db7b472 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Contributors ------------ -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov), [@lp1bp](https://github.com/lp1bp), [@stalniy](https://github.com/stalniy), [@liugogal](https://github.com/liugogal), [@lcaprini](https://github.com/lcaprini), [@jcdickman](https://github.com/jcdickman) +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov), [@lp1bp](https://github.com/lp1bp), [@stalniy](https://github.com/stalniy), [@liugogal](https://github.com/liugogal), [@lcaprini](https://github.com/lcaprini), [@jcdickman](https://github.com/jcdickman) [@shnist](https://github.com/shnist) A File Opener Plugin for Cordova (The Original Version) From 6bb67a9fa1ae86c74308663c46f33af7174b5039 Mon Sep 17 00:00:00 2001 From: shnist Date: Mon, 10 Dec 2018 16:45:11 +0000 Subject: [PATCH 68/76] 2.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 436e935..c543242 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-file-opener2", - "version": "2.0.19", + "version": "2.1.0", "description": "A File Opener Plugin for Cordova. (The Original Version)", "cordova": { "id": "cordova-plugin-file-opener2", From ee9058a3c51a46d5c9343a1833e3d401b396e2b9 Mon Sep 17 00:00:00 2001 From: shnist Date: Mon, 10 Dec 2018 16:46:35 +0000 Subject: [PATCH 69/76] Bumped the version to 2.1.0 --- CHANGELOG.md | 12 ++++++++++++ README.md | 2 +- plugin.xml | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..7116dad --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +Changelog +========================== + +2.1.0 +---------------- + +*Features* +* #234 Add optional android version support variable at installation + +*Bug fixes* +* #176 Various Android fixes. To verify it doesn't break anything, I tested opening a PDF and installing an APK on Android 4.1, 4.4, 5.0, 6.0, and 7.0. +* #155 iOS: use contentType if provided, otherwise fall back to file extension \ No newline at end of file diff --git a/README.md b/README.md index db7b472..5bcdac3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.0.19 +Current Version: 2.1.0 ---------------- Requirements diff --git a/plugin.xml b/plugin.xml index 38885f7..a368e8c 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + File Opener2 A File Opener Plugin for Cordova. (The Original Version) From fb9fcc7c9a5bb74a4b68b325b2daa12b384ff9f2 Mon Sep 17 00:00:00 2001 From: shnist Date: Tue, 11 Dec 2018 14:44:20 +0000 Subject: [PATCH 70/76] docs(): added npm version badge to readme --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 5bcdac3..71a2a40 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,7 @@ A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. -Current Version: 2.1.0 ----------------- +[![npm version](https://badge.fury.io/js/cordova-plugin-file-opener2.svg)](https://badge.fury.io/js/cordova-plugin-file-opener2) Requirements ------------- From 4f9d9b22643a031b52ef345ad086091b3eaf2d39 Mon Sep 17 00:00:00 2001 From: shnist Date: Tue, 11 Dec 2018 14:44:42 +0000 Subject: [PATCH 71/76] docs(): removed changelog as will construct this in the releases --- CHANGELOG.md | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 7116dad..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,12 +0,0 @@ -Changelog -========================== - -2.1.0 ----------------- - -*Features* -* #234 Add optional android version support variable at installation - -*Bug fixes* -* #176 Various Android fixes. To verify it doesn't break anything, I tested opening a PDF and installing an APK on Android 4.1, 4.4, 5.0, 6.0, and 7.0. -* #155 iOS: use contentType if provided, otherwise fall back to file extension \ No newline at end of file From d84b20e6209a7134dda39276dc1fa09a4229e604 Mon Sep 17 00:00:00 2001 From: Nathaniel van Diepen Date: Tue, 11 Dec 2018 08:59:29 -0700 Subject: [PATCH 72/76] Update fileOpener2Proxy.js --- src/windows/fileOpener2Proxy.js | 150 ++++++++++++++++---------------- 1 file changed, 76 insertions(+), 74 deletions(-) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index ce2dee6..b9c82d9 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -1,93 +1,95 @@ - var cordova = require('cordova'), - fileOpener2 = require('./FileOpener2'); +var cordova = require('cordova'), + fileOpener2 = require('./FileOpener2'); - var schemes = [ - { protocol: 'ms-app', getFile: getFileFromApplicationUri }, - { protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile - ] +var schemes = [ + { protocol: 'ms-app', getFile: getFileFromApplicationUri }, + { protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile +] - function nthIndex(str, pat, n) { - var L = str.length, i = -1; - while (n-- && i++ < L) { - i = str.indexOf(pat, i); - if (i < 0) break; - } - return i; - } +function nthIndex(str, pat, n) { + var L = str.length, i = -1; + while (n-- && i++ < L) { + i = str.indexOf(pat, i); + if (i < 0) break; + } + return i; +} - function getFileFromApplicationUri(uri) { - /* bad path from a file entry due to the last '//' - example: ms-appdata:///local//path/to/file - */ - var index = nthIndex(uri, "//", 3); - var newUri = uri.substr(0, index) + uri.substr(index + 1); +function getFileFromApplicationUri(uri) { + /* bad path from a file entry due to the last '//' + example: ms-appdata:///local//path/to/file + */ + var index = nthIndex(uri, "//", 3); + var newUri = uri.substr(0, index) + uri.substr(index + 1); - var applicationUri = new Windows.Foundation.Uri(newUri); + var applicationUri = new Windows.Foundation.Uri(newUri); - return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); - } + return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); +} - function getFileFromFileUri(uri) { - /* uri example: - cdvfile://localhost/persistent|temporary|another-fs-root/path/to/file - */ - var indexFrom = nthIndex(uri, "/", 3) + 1; - var indexTo = nthIndex(uri, "/", 4); - var whichFolder = uri.substring(indexFrom, indexTo); - var filePath = uri.substr(indexTo + 1); - var path = "\\" + filePath; +function getFileFromFileUri(uri) { + /* uri example: + cdvfile://localhost/persistent|temporary|another-fs-root/path/to/file + */ + var indexFrom = nthIndex(uri, "/", 3) + 1; + var indexTo = nthIndex(uri, "/", 4); + var whichFolder = uri.substring(indexFrom, indexTo); + var filePath = uri.substr(indexTo + 1); + var path = "\\" + filePath; - if (whichFolder == "persistent") { - path = Windows.Storage.ApplicationData.current.localFolder.path + path; - } - else { //temporary, note: no roaming management - path = Windows.Storage.ApplicationData.current.temporaryFolder.path + path; - } + if (whichFolder == "persistent") { + path = Windows.Storage.ApplicationData.current.localFolder.path + path; + } + else { //temporary, note: no roaming management + path = Windows.Storage.ApplicationData.current.temporaryFolder.path + path; + } - return getFileFromNativePath(path); - } + return getFileFromNativePath(path); +} - function getFileFromNativePath(path) { - var nativePath = path.split("/").join("\\"); +function getFileFromNativePath(path) { + var nativePath = path.split("/").join("\\"); - return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath); - } + return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath); +} - function getFileLoaderForScheme(path) { - var fileLoader = getFileFromNativePath; +function getFileLoaderForScheme(path) { + var fileLoader = getFileFromNativePath; - schemes.some(function (scheme) { - return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false; - }); + schemes.some(function (scheme) { + return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false; + }); - return fileLoader; - } + return fileLoader; +} - module.exports = { +module.exports = { - open: function (successCallback, errorCallback, args) { - - var path = args[0]; - - var getFile = getFileLoaderForScheme(path); - - getFile(path).then(function (file) { - var options = new Windows.System.LauncherOptions(); - - Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { - successCallback(); - }, function (error) { - errorCallback(error); - }); + open: function (successCallback, errorCallback, args) { + + var path = args[0]; + + var getFile = getFileLoaderForScheme(path); + try{ + getFile(path).then(function (file) { + var options = new Windows.System.LauncherOptions(); + + Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { + successCallback(); + }, function (error) { + errorCallback(error); + }); + }, function (error) { + console.log("Error while opening the file: "+error); + errorCallback(error); + }); + }catch(error){ + errorCallback(error); + } + } - }, function (error) { - console.log("Error while opening the file: "+error); - errorCallback(error); - }); - } - - }; +}; - require("cordova/exec/proxy").add("FileOpener2", module.exports); +require("cordova/exec/proxy").add("FileOpener2", module.exports); From 0c6cbedb172f8351570a3d57b4070db9e3268ecb Mon Sep 17 00:00:00 2001 From: Nathaniel van Diepen Date: Tue, 11 Dec 2018 09:02:14 -0700 Subject: [PATCH 73/76] Update fileOpener2Proxy.js --- src/windows/fileOpener2Proxy.js | 150 ++++++++++++++++---------------- 1 file changed, 76 insertions(+), 74 deletions(-) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index b9c82d9..d5d2e2d 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -1,95 +1,97 @@ -var cordova = require('cordova'), - fileOpener2 = require('./FileOpener2'); + var cordova = require('cordova'), + fileOpener2 = require('./FileOpener2'); -var schemes = [ - { protocol: 'ms-app', getFile: getFileFromApplicationUri }, - { protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile -] + var schemes = [ + { protocol: 'ms-app', getFile: getFileFromApplicationUri }, + { protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile + ] -function nthIndex(str, pat, n) { - var L = str.length, i = -1; - while (n-- && i++ < L) { - i = str.indexOf(pat, i); - if (i < 0) break; - } - return i; -} - -function getFileFromApplicationUri(uri) { - /* bad path from a file entry due to the last '//' - example: ms-appdata:///local//path/to/file - */ - var index = nthIndex(uri, "//", 3); - var newUri = uri.substr(0, index) + uri.substr(index + 1); - - var applicationUri = new Windows.Foundation.Uri(newUri); - - return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); -} - -function getFileFromFileUri(uri) { - /* uri example: - cdvfile://localhost/persistent|temporary|another-fs-root/path/to/file - */ - var indexFrom = nthIndex(uri, "/", 3) + 1; - var indexTo = nthIndex(uri, "/", 4); - var whichFolder = uri.substring(indexFrom, indexTo); - var filePath = uri.substr(indexTo + 1); - var path = "\\" + filePath; - - if (whichFolder == "persistent") { - path = Windows.Storage.ApplicationData.current.localFolder.path + path; - } - else { //temporary, note: no roaming management - path = Windows.Storage.ApplicationData.current.temporaryFolder.path + path; + function nthIndex(str, pat, n) { + var L = str.length, i = -1; + while (n-- && i++ < L) { + i = str.indexOf(pat, i); + if (i < 0) break; + } + return i; } - return getFileFromNativePath(path); -} + function getFileFromApplicationUri(uri) { + /* bad path from a file entry due to the last '//' + example: ms-appdata:///local//path/to/file + */ + var index = nthIndex(uri, "//", 3); + var newUri = uri.substr(0, index) + uri.substr(index + 1); -function getFileFromNativePath(path) { - var nativePath = path.split("/").join("\\"); + var applicationUri = new Windows.Foundation.Uri(newUri); - return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath); -} + return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); + } -function getFileLoaderForScheme(path) { - var fileLoader = getFileFromNativePath; + function getFileFromFileUri(uri) { + /* uri example: + cdvfile://localhost/persistent|temporary|another-fs-root/path/to/file + */ + var indexFrom = nthIndex(uri, "/", 3) + 1; + var indexTo = nthIndex(uri, "/", 4); + var whichFolder = uri.substring(indexFrom, indexTo); + var filePath = uri.substr(indexTo + 1); + var path = "\\" + filePath; - schemes.some(function (scheme) { - return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false; - }); + if (whichFolder == "persistent") { + path = Windows.Storage.ApplicationData.current.localFolder.path + path; + } + else { //temporary, note: no roaming management + path = Windows.Storage.ApplicationData.current.temporaryFolder.path + path; + } - return fileLoader; -} + return getFileFromNativePath(path); + } -module.exports = { + function getFileFromNativePath(path) { + var nativePath = path.split("/").join("\\"); - open: function (successCallback, errorCallback, args) { - - var path = args[0]; - - var getFile = getFileLoaderForScheme(path); - try{ - getFile(path).then(function (file) { - var options = new Windows.System.LauncherOptions(); + return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath); + } + + function getFileLoaderForScheme(path) { + var fileLoader = getFileFromNativePath; + + schemes.some(function (scheme) { + return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false; + }); + + return fileLoader; + } + + module.exports = { + + open: function (successCallback, errorCallback, args) { - Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { - successCallback(); - }, function (error) { + var path = args[0]; + + var getFile = getFileLoaderForScheme(path); + + getFile(path).then(function (file) { + var options = new Windows.System.LauncherOptions(); + + try{ + Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { + successCallback(); + }, function (error) { + errorCallback(error); + }); + }catch(error){ errorCallback(error); - }); + } + }, function (error) { console.log("Error while opening the file: "+error); errorCallback(error); }); - }catch(error){ - errorCallback(error); } - } + + }; -}; - -require("cordova/exec/proxy").add("FileOpener2", module.exports); + require("cordova/exec/proxy").add("FileOpener2", module.exports); From 85fa81fba36f3c0e7a0df332346780b5ec0096b5 Mon Sep 17 00:00:00 2001 From: Nathaniel van Diepen Date: Tue, 11 Dec 2018 09:03:22 -0700 Subject: [PATCH 74/76] Update fileOpener2Proxy.js --- src/windows/fileOpener2Proxy.js | 136 ++++++++++++++++---------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index d5d2e2d..8155002 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -1,97 +1,97 @@ - var cordova = require('cordova'), - fileOpener2 = require('./FileOpener2'); + var cordova = require('cordova'), + fileOpener2 = require('./FileOpener2'); - var schemes = [ + var schemes = [ { protocol: 'ms-app', getFile: getFileFromApplicationUri }, { protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile - ] + ] - function nthIndex(str, pat, n) { - var L = str.length, i = -1; - while (n-- && i++ < L) { - i = str.indexOf(pat, i); - if (i < 0) break; - } - return i; - } + function nthIndex(str, pat, n) { + var L = str.length, i = -1; + while (n-- && i++ < L) { + i = str.indexOf(pat, i); + if (i < 0) break; + } + return i; + } - function getFileFromApplicationUri(uri) { - /* bad path from a file entry due to the last '//' + function getFileFromApplicationUri(uri) { + /* bad path from a file entry due to the last '//' example: ms-appdata:///local//path/to/file */ - var index = nthIndex(uri, "//", 3); - var newUri = uri.substr(0, index) + uri.substr(index + 1); + var index = nthIndex(uri, "//", 3); + var newUri = uri.substr(0, index) + uri.substr(index + 1); - var applicationUri = new Windows.Foundation.Uri(newUri); + var applicationUri = new Windows.Foundation.Uri(newUri); - return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); - } + return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); + } - function getFileFromFileUri(uri) { - /* uri example: + function getFileFromFileUri(uri) { + /* uri example: cdvfile://localhost/persistent|temporary|another-fs-root/path/to/file */ - var indexFrom = nthIndex(uri, "/", 3) + 1; - var indexTo = nthIndex(uri, "/", 4); - var whichFolder = uri.substring(indexFrom, indexTo); - var filePath = uri.substr(indexTo + 1); - var path = "\\" + filePath; + var indexFrom = nthIndex(uri, "/", 3) + 1; + var indexTo = nthIndex(uri, "/", 4); + var whichFolder = uri.substring(indexFrom, indexTo); + var filePath = uri.substr(indexTo + 1); + var path = "\\" + filePath; - if (whichFolder == "persistent") { - path = Windows.Storage.ApplicationData.current.localFolder.path + path; - } - else { //temporary, note: no roaming management - path = Windows.Storage.ApplicationData.current.temporaryFolder.path + path; - } + if (whichFolder == "persistent") { + path = Windows.Storage.ApplicationData.current.localFolder.path + path; + } + else { //temporary, note: no roaming management + path = Windows.Storage.ApplicationData.current.temporaryFolder.path + path; + } - return getFileFromNativePath(path); - } + return getFileFromNativePath(path); + } - function getFileFromNativePath(path) { - var nativePath = path.split("/").join("\\"); + function getFileFromNativePath(path) { + var nativePath = path.split("/").join("\\"); - return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath); - } + return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath); + } - function getFileLoaderForScheme(path) { - var fileLoader = getFileFromNativePath; + function getFileLoaderForScheme(path) { + var fileLoader = getFileFromNativePath; - schemes.some(function (scheme) { - return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false; - }); + schemes.some(function (scheme) { + return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false; + }); - return fileLoader; - } + return fileLoader; + } - module.exports = { + module.exports = { - open: function (successCallback, errorCallback, args) { - - var path = args[0]; - - var getFile = getFileLoaderForScheme(path); - - getFile(path).then(function (file) { - var options = new Windows.System.LauncherOptions(); - + open: function (successCallback, errorCallback, args) { + + var path = args[0]; + + var getFile = getFileLoaderForScheme(path); + + getFile(path).then(function (file) { + var options = new Windows.System.LauncherOptions(); + try{ - Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { - successCallback(); - }, function (error) { - errorCallback(error); - }); + Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { + successCallback(); + }, function (error) { + errorCallback(error); + }); }catch(error){ errorCallback(error); } - }, function (error) { - console.log("Error while opening the file: "+error); - errorCallback(error); - }); - } - - }; + }, function (error) { + console.log("Error while opening the file: "+error); + errorCallback(error); + }); + } + + }; - require("cordova/exec/proxy").add("FileOpener2", module.exports); + require("cordova/exec/proxy").add("FileOpener2", module.exports); From 4d70f315dfd4205b21a0b22a2746416a9c3c0595 Mon Sep 17 00:00:00 2001 From: shnist Date: Tue, 11 Dec 2018 17:11:39 +0000 Subject: [PATCH 75/76] docs(): added docs for installing apk / ipa file from marketplace. closes #57 --- README.md | 150 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 85 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 71a2a40..37672f1 100644 --- a/README.md +++ b/README.md @@ -16,58 +16,77 @@ Requirements Installation ------------- - $ cordova plugin add cordova-plugin-file-opener2 - $ cordova plugin add cordova-plugin-file-opener2 --variable ANDROID_SUPPORT_VERSION={required version} +```shell +$ cordova plugin add cordova-plugin-file-opener2 +$ cordova plugin add cordova-plugin-file-opener2 --variable ANDROID_SUPPORT_VERSION={required version} +``` Usage ------ - cordova.plugins.fileOpener2.open( - filePath, - fileMIMEType, - { - error : function(){ }, - success : function(){ } - } - ); +```javascript +cordova.plugins.fileOpener2.open( + filePath, + fileMIMEType, + { + error : function(){ }, + success : function(){ } + } +); +``` Examples -------- Open an APK install dialog: - cordova.plugins.fileOpener2.open( - '/sdcard/Download/gmail.apk', - 'application/vnd.android.package-archive' - ); +```javascript +cordova.plugins.fileOpener2.open( + '/sdcard/Download/gmail.apk', + 'application/vnd.android.package-archive' +); +``` + +Install From Market: to install an APK from a market place, such as Google Play or the App Store, you can use an `` tag in combination with the `market://` protocol: + +```html +Install from Google Play +Install from App Store +``` + +or in code: +```javascript +window.open("[market:// or itms-apps:// link]","_system"); +``` Open a PDF document with the default PDF reader and optional callback object: - - cordova.plugins.fileOpener2.open( - '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf - 'application/pdf', - { - error : function(e) { - console.log('Error status: ' + e.status + ' - Error message: ' + e.message); - }, - success : function () { - console.log('file opened successfully'); - } +```javascript +cordova.plugins.fileOpener2.open( + '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf + 'application/pdf', + { + error : function(e) { + console.log('Error status: ' + e.status + ' - Error message: ' + e.message); + }, + success : function () { + console.log('file opened successfully'); } - ); - + } +); +``` Open a system modal to open PDF document with one of the already installed app and optional callback object: - - cordova.plugins.fileOpener2.showOpenWithDialog( - '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf - 'application/pdf', - { - error : function(e) { - console.log('Error status: ' + e.status + ' - Error message: ' + e.message); - }, - success : function () { - console.log('file opened successfully'); - } +```javascript +cordova.plugins.fileOpener2.showOpenWithDialog( + '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf + 'application/pdf', + { + error : function(e) { + console.log('Error status: ' + e.status + ' - Error message: ' + e.message); + }, + success : function () { + console.log('file opened successfully'); } - ); + } +); +``` Notes ------ @@ -78,16 +97,17 @@ Notes - If you are wondering what MIME-type should you pass as the second argument to `open` function, [here is a list of all known MIME-types](http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co) + Android APK installation limitation --- The following limitations apply when opening an APK file for installation: - On Android 8+, your application must have the `ACTION_INSTALL_PACKAGE` permission. You can add it by adding this to your app's `config.xml` file: -``` - - - - - +```xml + + + + + ``` - Before Android 7, you can only install APKs from the "external" partition. For example, you can install from `cordova.file.externalDataDirectory`, but **not** from `cordova.file.dataDirectory`. Android 7+ does not have this limitation. @@ -99,30 +119,30 @@ The following functions are available in Android platform: `.uninstall(packageId, callbackContext)` --- Uninstall a package with its id. - - cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', { - error : function(e) { - console.log('Error status: ' + e.status + ' - Error message: ' + e.message); - }, - success : function() { - console.log('Uninstall intent activity started.'); - } - }); - +```javascript +cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', { + error : function(e) { + console.log('Error status: ' + e.status + ' - Error message: ' + e.message); + }, + success : function() { + console.log('Uninstall intent activity started.'); + } +}); +``` `.appIsInstalled(packageId, callbackContext)` --- Check if an app is already installed. - - cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', { - success : function(res) { - if (res.status === 0) { - console.log('Adobe Reader is not installed.'); - } else { - console.log('Adobe Reader is installed.') - } +```javascript +cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', { + success : function(res) { + if (res.status === 0) { + console.log('Adobe Reader is not installed.'); + } else { + console.log('Adobe Reader is installed.') } - }); - + } +}); +``` --- LICENSE From 8a884711c10ca9671fe277ae101752d40287af68 Mon Sep 17 00:00:00 2001 From: shnist Date: Tue, 11 Dec 2018 17:14:06 +0000 Subject: [PATCH 76/76] docs(): updated contributors list in readme and moved to bottom. --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 37672f1..4111eaa 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,3 @@ -Contributors ------------- -[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov), [@lp1bp](https://github.com/lp1bp), [@stalniy](https://github.com/stalniy), [@liugogal](https://github.com/liugogal), [@lcaprini](https://github.com/lcaprini), [@jcdickman](https://github.com/jcdickman) [@shnist](https://github.com/shnist) - - A File Opener Plugin for Cordova (The Original Version) ========================== This plugin will open a file on your device file system with its default application. @@ -145,6 +140,12 @@ cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', { ``` --- +Contributors +------------ +[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V), [@WuglyakBolgoink](https://github.com/WuglyakBolgoink), [@lincolnthree](https://github.com/lincolnthree), [@rocco](https://github.com/rocco/), [@FrankFenton](https://github.com/FrankFenton), [@MHolmes91](https://github.com/MHolmes91), [@souly1](https://github.com/souly1), [@diogodias86](https://github.com/diogodias86), [@Arxi](https://github.com/Arxi), [@vzharkov](https://github.com/vzharkov), [@lp1bp](https://github.com/lp1bp), [@stalniy](https://github.com/stalniy), [@liugogal](https://github.com/liugogal), [@lcaprini](https://github.com/lcaprini), [@jcdickman](https://github.com/jcdickman) [@shnist](https://github.com/shnist) [@Eeems](https://github.com/Eeems) + +--- + LICENSE -------- The MIT License (MIT)