diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 0000000..85b6334
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,38 @@
+---
+name: Bug report
+about: Create a report to help us improve
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+### Expected Behaviour
+
+### Actual Behaviour
+
+### Reproduce Scenario (including but not limited to)
+
+#### Steps to Reproduce
+
+#### Platform and Version (eg. Android 5.0 or iOS 9.2.1)
+
+#### (Android) What device vendor (e.g. Samsung, HTC, Sony...)
+
+#### Cordova CLI info
+
+ cordova info
+
+Here is the output:
+
+
+#### Plugin version
+
+ cordova plugin version | grep cordova-plugin-file-opener2
+
+Here is the output:
+
+
+#### Sample Code that illustrates the problem
+
+#### Logs taken while reproducing problem
diff --git a/README.md b/README.md
index 0f64971..fe56e6d 100644
--- a/README.md
+++ b/README.md
@@ -1,149 +1,184 @@
-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)
-
-
-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
-----------------
-
-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');
- }
- }
- );
-
-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
-------
-
-- 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:
-
-`.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.
+# A File Opener Plugin for Cordova (The Original Version)
+
+[![Latest Stable Version](https://img.shields.io/npm/v/cordova-plugin-file-opener2.svg)](https://www.npmjs.com/package/cordova-plugin-file-opener2) [![Total Downloads](https://img.shields.io/npm/dt/cordova-plugin-file-opener2.svg)](https://npm-stat.com/charts.html?package=cordova-plugin-file-opener2) [![Build Status](https://travis-ci.org/apache/cordova-plugin-file-opener2.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-file-opener2)
+
+This plugin will open a file on your device file system with its default application.
+
+```js
+cordova.plugins.fileOpener2.open(
+ filePath,
+ fileMIMEType,
+ {
+ error : function(){ },
+ success : function(){ }
+ }
+);
+```
+
+## Installation
+
+```shell
+$ cordova plugin add cordova-plugin-file-opener2
+```
+
+From release `2.1.0` you can also set the android support version
+```shell
+$ cordova plugin add cordova-plugin-file-opener2 --variable ANDROID_SUPPORT_V4_VERSION={required version}
+```
+
+## Requirements
+
+The following platforms and versions are supported by the latest release:
+
+- Android 4.4+ / iOS 9+ / WP8 / Windows
+- Cordova CLI 7.0 or higher
+
+Cordova CLI 6.0 is supported by 2.0.19, but there are a number of issues, particularly with Android builds (see [232](https://github.com/pwlin/cordova-plugin-file-opener2/issues/232) [203](https://github.com/pwlin/cordova-plugin-file-opener2/issues/203) [207](https://github.com/pwlin/cordova-plugin-file-opener2/issues/207)). Using the [cordova-android-support-gradle-release](https://github.com/dpa99c/cordova-android-support-gradle-release) plugin may help.
+
+## fileOpener2.open(filePath, mimeType, options)
+
+Opens a file
+
+### Supported Platforms
+
+- Android 4.4+
+- iOS 9+
+- Windows
+- WP8
+
+### Quick Examples
+Open an APK install dialog:
+
+```javascript
+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:
+
+```js
+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');
+ }
+ }
+);
+```
+
+### Market place installation
+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:
+
+```js
+window.open("[market:// or itms-apps:// link]","_system");
+```
+
+## fileOpener2.showOpenWithDialog(filePath, mimeType, options)
+
+Opens with system modal to open file with an already installed app.
+
+### Supported Platforms
+
+- Android 4.4+
+- iOS 9+
+
+### Quick Example
+
+```js
+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');
+ }
+ }
+);
+```
+
+## fileOpener2.uninstall(packageId, callbackContext)
+
+Uninstall a package with its ID
+
+### Supported Platforms
+
+- Android 4.4+
+
+### Quick Example
+```js
+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.');
+ }
+});
+```
+
+## fileOpener2.appIsInstalled(packageId, callbackContext)
+
+Check if an app is already installed.
+
+### Supported Platforms
+
+- Android 4.4+
+
+### Quick Example
+```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.')
+ }
+ }
+});
+```
+---
+
+## 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.
+
+---
+
+## 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)
+
+
+---
+
+
diff --git a/package.json b/package.json
index 436e935..bff246c 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-file-opener2",
- "version": "2.0.19",
+ "version": "2.1.4",
"description": "A File Opener Plugin for Cordova. (The Original Version)",
"cordova": {
"id": "cordova-plugin-file-opener2",
@@ -22,12 +22,9 @@
"cordova-wp8",
"cordova-windows"
],
- "engines": [
- {
- "name": "cordova",
- "version": ">=3.0.0"
- }
- ],
+ "engines": {
+ "cordova": ">=6.0.0"
+ },
"author": {
"name": "pwlin05@gmail.com"
},
diff --git a/plugin.xml b/plugin.xml
index 7822b53..a261d14 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -1,5 +1,5 @@
-
+
File Opener2
A File Opener Plugin for Cordova. (The Original Version)
@@ -31,7 +31,8 @@
-
+
+
diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m
index 7eb08eb..270b7ab 100644
--- a/src/ios/FileOpener2.m
+++ b/src/ios/FileOpener2.m
@@ -104,6 +104,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@implementation FileOpener2 (UIDocumentInteractionControllerDelegate)
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
- return self.cdvViewController;
+ UIViewController *presentingViewController = self.viewController;
+ if (presentingViewController.view.window != [UIApplication sharedApplication].keyWindow){
+ presentingViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
+ }
+
+ while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]){
+ presentingViewController = presentingViewController.presentedViewController;
+ }
+ return presentingViewController;
}
@end
diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js
index ce2dee6..8155002 100644
--- a/src/windows/fileOpener2Proxy.js
+++ b/src/windows/fileOpener2Proxy.js
@@ -75,11 +75,15 @@
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);
- });
+ 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);
diff --git a/www/plugins.FileOpener2.js b/www/plugins.FileOpener2.js
index ebe9313..e8b2258 100644
--- a/www/plugins.FileOpener2.js
+++ b/www/plugins.FileOpener2.js
@@ -27,7 +27,7 @@ var exec = require('cordova/exec');
function FileOpener2() {}
FileOpener2.prototype.open = function (fileName, contentType, callbackContext) {
- contentType = contentType || '';
+ contentType = contentType || '';
callbackContext = callbackContext || {};
exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType]);
};