Merge branch 'master' into master

This commit is contained in:
Aaron Faber 2019-02-12 14:51:58 +00:00 committed by GitHub
commit 4f868e4441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 248 additions and 165 deletions

38
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@ -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

197
README.md
View File

@ -1,47 +1,65 @@
Contributors # A File Opener Plugin for Cordova (The Original Version)
------------
[@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)
[![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)
A File Opener Plugin for Cordova (The Original Version)
==========================
This plugin will open a file on your device file system with its default application. This plugin will open a file on your device file system with its default application.
Current Version: 2.0.19 ```js
---------------- cordova.plugins.fileOpener2.open(
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, filePath,
fileMIMEType, fileMIMEType,
{ {
error : function(){ }, error : function(){ },
success : function(){ } success : function(){ }
} }
); );
```
Examples ## 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: Open an APK install dialog:
cordova.plugins.fileOpener2.open( ```javascript
cordova.plugins.fileOpener2.open(
'/sdcard/Download/gmail.apk', '/sdcard/Download/gmail.apk',
'application/vnd.android.package-archive' 'application/vnd.android.package-archive'
); );
```
Open a PDF document with the default PDF reader and optional callback object: Open a PDF document with the default PDF reader and optional callback object:
cordova.plugins.fileOpener2.open( ```js
cordova.plugins.fileOpener2.open(
'/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
'application/pdf', 'application/pdf',
{ {
@ -52,11 +70,35 @@ Open a PDF document with the default PDF reader and optional callback object:
console.log('file opened successfully'); console.log('file opened successfully');
} }
} }
); );
```
Open a system modal to open PDF document with one of the already installed app and optional callback object: ### 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 `<a>` tag in combination with the `market://` protocol:
cordova.plugins.fileOpener2.showOpenWithDialog( ```html
<a href="market://details?id=xxxx" target="_system">Install from Google Play</a>
<a href="itms-apps://itunes.apple.com/app/my-app/idxxxxxxxx?mt=8" target="_system">Install from App Store</a>
```
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 '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
'application/pdf', 'application/pdf',
{ {
@ -67,53 +109,40 @@ Open a system modal to open PDF document with one of the already installed app a
console.log('file opened successfully'); 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 `<preference name="iosPersistentFileLocation" value="Library" />` 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:
```
<platform name="android">
<config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
</config-file>
</platform>
``` ```
- 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. ## fileOpener2.uninstall(packageId, callbackContext)
Additional Android Functions Uninstall a package with its ID
---
The following functions are available in Android platform:
`.uninstall(packageId, callbackContext)` ### Supported Platforms
---
Uninstall a package with its id.
cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', { - Android 4.4+
### Quick Example
```js
cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', {
error : function(e) { 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() { success : function() {
console.log('Uninstall intent activity started.'); console.log('Uninstall intent activity started.');
} }
}); });
```
## fileOpener2.appIsInstalled(packageId, callbackContext)
`.appIsInstalled(packageId, callbackContext)`
---
Check if an app is already installed. Check if an app is already installed.
cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', { ### Supported Platforms
- Android 4.4+
### Quick Example
```javascript
cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', {
success : function(res) { success : function(res) {
if (res.status === 0) { if (res.status === 0) {
console.log('Adobe Reader is not installed.'); console.log('Adobe Reader is not installed.');
@ -121,29 +150,35 @@ Check if an app is already installed.
console.log('Adobe Reader is installed.') 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
<platform name="android">
<config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
</config-file>
</platform>
```
- 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.
--- ---
LICENSE ## Notes
--------
The MIT License (MIT)
Copyright (c) 2013 pwlin - pwlin05@gmail.com - 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.
Permission is hereby granted, free of charge, to any person obtaining a copy of - [It is reported](https://github.com/pwlin/cordova-plugin-file-opener2/issues/2#issuecomment-41295793) that in iOS, you might need to remove `<preference name="iosPersistentFileLocation" value="Library" />` from your `config.xml`
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to - 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)
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.

View File

@ -1,6 +1,6 @@
{ {
"name": "cordova-plugin-file-opener2", "name": "cordova-plugin-file-opener2",
"version": "2.0.19", "version": "2.1.4",
"description": "A File Opener Plugin for Cordova. (The Original Version)", "description": "A File Opener Plugin for Cordova. (The Original Version)",
"cordova": { "cordova": {
"id": "cordova-plugin-file-opener2", "id": "cordova-plugin-file-opener2",
@ -22,12 +22,9 @@
"cordova-wp8", "cordova-wp8",
"cordova-windows" "cordova-windows"
], ],
"engines": [ "engines": {
{ "cordova": ">=6.0.0"
"name": "cordova", },
"version": ">=3.0.0"
}
],
"author": { "author": {
"name": "pwlin05@gmail.com" "name": "pwlin05@gmail.com"
}, },

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-file-opener2" version="2.0.19"> <plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-file-opener2" version="2.1.4">
<name>File Opener2</name> <name>File Opener2</name>
<description>A File Opener Plugin for Cordova. (The Original Version)</description> <description>A File Opener Plugin for Cordova. (The Original Version)</description>
@ -31,7 +31,8 @@
</provider> </provider>
</config-file> </config-file>
<source-file src="src/android/res/xml/opener_paths.xml" target-dir="res/xml" /> <source-file src="src/android/res/xml/opener_paths.xml" target-dir="res/xml" />
<framework src="com.android.support:support-v4:26.0.0-alpha1" /> <preference name="ANDROID_SUPPORT_V4_VERSION" default="27.+"/>
<framework src="com.android.support:support-v4:$ANDROID_SUPPORT_V4_VERSION"/>
</platform> </platform>
<!-- iOS --> <!-- iOS -->

View File

@ -104,6 +104,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@implementation FileOpener2 (UIDocumentInteractionControllerDelegate) @implementation FileOpener2 (UIDocumentInteractionControllerDelegate)
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { - (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 @end

View File

@ -75,11 +75,15 @@
getFile(path).then(function (file) { getFile(path).then(function (file) {
var options = new Windows.System.LauncherOptions(); var options = new Windows.System.LauncherOptions();
try{
Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { Windows.System.Launcher.launchFileAsync(file, options).then(function (success) {
successCallback(); successCallback();
}, function (error) { }, function (error) {
errorCallback(error); errorCallback(error);
}); });
}catch(error){
errorCallback(error);
}
}, function (error) { }, function (error) {
console.log("Error while opening the file: "+error); console.log("Error while opening the file: "+error);