mirror of
https://gitee.com/shuto/cordova-plugin-file-opener2.git
synced 2025-01-31 12:02:49 +08:00
Merge branch 'master' into master
This commit is contained in:
commit
4f868e4441
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal 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
|
333
README.md
333
README.md
@ -1,149 +1,184 @@
|
|||||||
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)
|
||||||
|
|
||||||
|
This plugin will open a file on your device file system with its default application.
|
||||||
A File Opener Plugin for Cordova (The Original Version)
|
|
||||||
==========================
|
```js
|
||||||
This plugin will open a file on your device file system with its default application.
|
cordova.plugins.fileOpener2.open(
|
||||||
|
filePath,
|
||||||
Current Version: 2.0.19
|
fileMIMEType,
|
||||||
----------------
|
{
|
||||||
|
error : function(){ },
|
||||||
Requirements
|
success : function(){ }
|
||||||
-------------
|
}
|
||||||
- Android 4 or higher / iOS 6 or higher / WP8
|
);
|
||||||
- Cordova 3.0 or higher
|
```
|
||||||
|
|
||||||
Installation
|
## Installation
|
||||||
-------------
|
|
||||||
cordova plugin add cordova-plugin-file-opener2
|
```shell
|
||||||
|
$ cordova plugin add cordova-plugin-file-opener2
|
||||||
Usage
|
```
|
||||||
------
|
|
||||||
cordova.plugins.fileOpener2.open(
|
From release `2.1.0` you can also set the android support version
|
||||||
filePath,
|
```shell
|
||||||
fileMIMEType,
|
$ cordova plugin add cordova-plugin-file-opener2 --variable ANDROID_SUPPORT_V4_VERSION={required version}
|
||||||
{
|
```
|
||||||
error : function(){ },
|
|
||||||
success : function(){ }
|
## Requirements
|
||||||
}
|
|
||||||
);
|
The following platforms and versions are supported by the latest release:
|
||||||
|
|
||||||
Examples
|
- Android 4.4+ / iOS 9+ / WP8 / Windows
|
||||||
--------
|
- Cordova CLI 7.0 or higher
|
||||||
Open an APK install dialog:
|
|
||||||
|
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.
|
||||||
cordova.plugins.fileOpener2.open(
|
|
||||||
'/sdcard/Download/gmail.apk',
|
## fileOpener2.open(filePath, mimeType, options)
|
||||||
'application/vnd.android.package-archive'
|
|
||||||
);
|
Opens a file
|
||||||
|
|
||||||
Open a PDF document with the default PDF reader and optional callback object:
|
### Supported Platforms
|
||||||
|
|
||||||
cordova.plugins.fileOpener2.open(
|
- Android 4.4+
|
||||||
'/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
|
- iOS 9+
|
||||||
'application/pdf',
|
- Windows
|
||||||
{
|
- WP8
|
||||||
error : function(e) {
|
|
||||||
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
|
### Quick Examples
|
||||||
},
|
Open an APK install dialog:
|
||||||
success : function () {
|
|
||||||
console.log('file opened successfully');
|
```javascript
|
||||||
}
|
cordova.plugins.fileOpener2.open(
|
||||||
}
|
'/sdcard/Download/gmail.apk',
|
||||||
);
|
'application/vnd.android.package-archive'
|
||||||
|
);
|
||||||
Open a system modal to open PDF document with one of the already installed app and optional callback object:
|
```
|
||||||
|
|
||||||
cordova.plugins.fileOpener2.showOpenWithDialog(
|
Open a PDF document with the default PDF reader and optional callback object:
|
||||||
'/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
|
|
||||||
'application/pdf',
|
```js
|
||||||
{
|
cordova.plugins.fileOpener2.open(
|
||||||
error : function(e) {
|
'/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
|
||||||
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
|
'application/pdf',
|
||||||
},
|
{
|
||||||
success : function () {
|
error : function(e) {
|
||||||
console.log('file opened successfully');
|
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.
|
|
||||||
|
### Market place installation
|
||||||
- [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`
|
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:
|
||||||
|
|
||||||
- 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)
|
```html
|
||||||
|
<a href="market://details?id=xxxx" target="_system">Install from Google Play</a>
|
||||||
Android APK installation limitation
|
<a href="itms-apps://itunes.apple.com/app/my-app/idxxxxxxxx?mt=8" target="_system">Install from App Store</a>
|
||||||
---
|
```
|
||||||
The following limitations apply when opening an APK file for installation:
|
or in code:
|
||||||
- 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:
|
|
||||||
```
|
```js
|
||||||
<platform name="android">
|
window.open("[market:// or itms-apps:// link]","_system");
|
||||||
<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>
|
## fileOpener2.showOpenWithDialog(filePath, mimeType, options)
|
||||||
</platform>
|
|
||||||
```
|
Opens with system modal to open file with an already installed app.
|
||||||
|
|
||||||
- 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.
|
### Supported Platforms
|
||||||
|
|
||||||
Additional Android Functions
|
- Android 4.4+
|
||||||
---
|
- iOS 9+
|
||||||
The following functions are available in Android platform:
|
|
||||||
|
### Quick Example
|
||||||
`.uninstall(packageId, callbackContext)`
|
|
||||||
---
|
```js
|
||||||
Uninstall a package with its id.
|
cordova.plugins.fileOpener2.showOpenWithDialog(
|
||||||
|
'/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
|
||||||
cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', {
|
'application/pdf',
|
||||||
error : function(e) {
|
{
|
||||||
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
|
error : function(e) {
|
||||||
},
|
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
|
||||||
success : function() {
|
},
|
||||||
console.log('Uninstall intent activity started.');
|
success : function () {
|
||||||
}
|
console.log('file opened successfully');
|
||||||
});
|
}
|
||||||
|
}
|
||||||
`.appIsInstalled(packageId, callbackContext)`
|
);
|
||||||
---
|
```
|
||||||
Check if an app is already installed.
|
|
||||||
|
## fileOpener2.uninstall(packageId, callbackContext)
|
||||||
cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', {
|
|
||||||
success : function(res) {
|
Uninstall a package with its ID
|
||||||
if (res.status === 0) {
|
|
||||||
console.log('Adobe Reader is not installed.');
|
### Supported Platforms
|
||||||
} else {
|
|
||||||
console.log('Adobe Reader is installed.')
|
- 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);
|
||||||
LICENSE
|
},
|
||||||
--------
|
success : function() {
|
||||||
The MIT License (MIT)
|
console.log('Uninstall intent activity started.');
|
||||||
|
}
|
||||||
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
|
## fileOpener2.appIsInstalled(packageId, callbackContext)
|
||||||
the Software without restriction, including without limitation the rights to
|
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
Check if an app is already installed.
|
||||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
subject to the following conditions:
|
### Supported Platforms
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
- Android 4.4+
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
### Quick Example
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
```javascript
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', {
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
success : function(res) {
|
||||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
if (res.status === 0) {
|
||||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
console.log('Adobe Reader is not installed.');
|
||||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
} 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
|
||||||
|
<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.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
11
package.json
11
package.json
@ -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"
|
||||||
},
|
},
|
||||||
|
@ -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 -->
|
||||||
|
@ -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
|
||||||
|
@ -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();
|
||||||
|
|
||||||
Windows.System.Launcher.launchFileAsync(file, options).then(function (success) {
|
try{
|
||||||
successCallback();
|
Windows.System.Launcher.launchFileAsync(file, options).then(function (success) {
|
||||||
}, function (error) {
|
successCallback();
|
||||||
errorCallback(error);
|
}, function (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);
|
||||||
|
@ -27,7 +27,7 @@ var exec = require('cordova/exec');
|
|||||||
function FileOpener2() {}
|
function FileOpener2() {}
|
||||||
|
|
||||||
FileOpener2.prototype.open = function (fileName, contentType, callbackContext) {
|
FileOpener2.prototype.open = function (fileName, contentType, callbackContext) {
|
||||||
contentType = contentType || '';
|
contentType = contentType || '';
|
||||||
callbackContext = callbackContext || {};
|
callbackContext = callbackContext || {};
|
||||||
exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType]);
|
exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType]);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user