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
|
173
README.md
173
README.md
@ -1,26 +1,10 @@
|
||||
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)
|
||||
|
||||
[![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.
|
||||
|
||||
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
|
||||
------
|
||||
```js
|
||||
cordova.plugins.fileOpener2.open(
|
||||
filePath,
|
||||
fileMIMEType,
|
||||
@ -29,18 +13,52 @@ Usage
|
||||
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:
|
||||
|
||||
```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',
|
||||
@ -53,9 +71,33 @@ 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:
|
||||
### 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:
|
||||
|
||||
```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
|
||||
'application/pdf',
|
||||
@ -68,38 +110,18 @@ Open a system modal to open PDF document with one of the already installed app a
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
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
|
||||
---
|
||||
The following functions are available in Android platform:
|
||||
Uninstall a package with its ID
|
||||
|
||||
`.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);
|
||||
@ -108,11 +130,18 @@ Uninstall a package with its id.
|
||||
console.log('Uninstall intent activity started.');
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## fileOpener2.appIsInstalled(packageId, callbackContext)
|
||||
|
||||
`.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) {
|
||||
@ -122,28 +151,34 @@ Check if an app is already 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
|
||||
--------
|
||||
The MIT License (MIT)
|
||||
## Notes
|
||||
|
||||
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
|
||||
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:
|
||||
- [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)
|
||||
|
||||
|
||||
---
|
||||
|
||||
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.
|
||||
|
11
package.json
11
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"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?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>
|
||||
<description>A File Opener Plugin for Cordova. (The Original Version)</description>
|
||||
@ -31,7 +31,8 @@
|
||||
</provider>
|
||||
</config-file>
|
||||
<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>
|
||||
|
||||
<!-- iOS -->
|
||||
|
@ -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
|
||||
|
@ -75,11 +75,15 @@
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user