├── .github
└── ISSUE_TEMPLATE
│ └── bug_report.md
├── .gitignore
├── LICENSE
├── README.md
├── package.json
├── plugin.xml
├── src
├── android
│ ├── io
│ │ └── github
│ │ │ └── pwlin
│ │ │ └── cordova
│ │ │ └── plugins
│ │ │ └── fileopener2
│ │ │ ├── FileOpener2.java
│ │ │ └── FileProvider.java
│ └── res
│ │ └── xml
│ │ └── opener_paths.xml
├── browser
│ ├── FileOpener2.js
│ └── FileSaver.min.js
├── electron
│ └── FileOpener2.js
├── ios
│ ├── FileOpener2.h
│ └── FileOpener2.m
└── windows
│ └── fileOpener2Proxy.js
└── www
├── browser
└── isChrome.js
└── plugins.FileOpener2.js
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | ### Expected Behaviour
11 |
12 | ### Actual Behaviour
13 |
14 | ### Reproduce Scenario (including but not limited to)
15 |
16 | #### Steps to Reproduce
17 |
18 | #### Platform and Version (eg. Android 5.0 or iOS 9.2.1)
19 |
20 | #### (Android) What device vendor (e.g. Samsung, HTC, Sony...)
21 |
22 | #### Cordova CLI info
23 |
24 | cordova info
25 |
26 | Here is the output:
27 |
28 |
29 | #### Plugin version
30 |
31 | cordova plugin version | grep cordova-plugin-file-opener2
32 |
33 | Here is the output:
34 |
35 |
36 | #### Sample Code that illustrates the problem
37 |
38 | #### Logs taken while reproducing problem
39 | Run
40 |
41 | `adb logcat PluginManager:V CordovaPlugin:V CordovaLog:V chromium:V *:S`
42 |
43 | while testing the bug in your app to get some output from your error. This will help you to understand more about the nature of your problem.
44 |
45 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 | *.metals
3 | *.vscode
4 |
5 | # Package Files #
6 | *.jar
7 | *.war
8 | *.ear
9 | *.bak
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 pwlin - pwlin05@gmail.com
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ⛔️ NO LONGER MAINTAINED ⛔️
2 |
3 | This plugin was originally built back in 2013 to provide an easy way to open files in Cordova applications. Since 2018 the plugin has not been actively maintained, with only the occaisional release to support updates from the community. Due to signficant changes in the way that Android handles permissions from version 11 onwards, this plugin does not work with Android 11 or later and would require significant changes to make this happen.
4 |
5 | If someone would like to take on this work and maintain the plugin moving forward please get in touch.
6 |
7 | ----------
8 |
9 | # A File Opener Plugin for Cordova
10 |
11 | [](https://www.npmjs.com/package/cordova-plugin-file-opener2) [](https://npm-stat.com/charts.html?package=cordova-plugin-file-opener2)
12 |
13 | This plugin will open a file on your device file system with its default application.
14 |
15 | ```js
16 | cordova.plugins.fileOpener2.open(
17 | filePath,
18 | fileMIMEType,
19 | {
20 | error : function(){ },
21 | success : function(){ }
22 | }
23 | );
24 | ```
25 |
26 | ## Installation
27 |
28 | ```shell
29 | $ cordova plugin add cordova-plugin-file-opener2
30 | ```
31 |
32 | ## Requirements
33 |
34 | The following platforms and versions are supported by the latest release:
35 |
36 | - Android 5.1+ / iOS 9+ / Windows / Electron
37 | - Cordova CLI 7.0 or higher
38 |
39 | 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.
40 |
41 | ### Support for Android 11 and later
42 | There have been [reports](https://github.com/pwlin/cordova-plugin-file-opener2/issues/310) of issues using this plugin with Android 11 and later.
43 |
44 | ### Edit support
45 | The plugin currently does *not* support the editing of files on Android. It may support editing on iOS, but this has not been tested.
46 |
47 | ## fileOpener2.open(filePath, mimeType, options)
48 |
49 | Opens a file
50 |
51 | ### Supported Platforms
52 |
53 | - Android 5.1+
54 | - iOS 9+
55 | - Windows
56 | - Electron
57 |
58 | ### Quick Examples
59 | Open an APK install dialog:
60 |
61 | ```javascript
62 | cordova.plugins.fileOpener2.open(
63 | '/Downloads/gmail.apk',
64 | 'application/vnd.android.package-archive'
65 | );
66 | ```
67 |
68 | Open a PDF document with the default PDF reader and optional callback object:
69 |
70 | ```js
71 | cordova.plugins.fileOpener2.open(
72 | '/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Downloads/starwars.pdf
73 | 'application/pdf',
74 | {
75 | error : function(e) {
76 | console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
77 | },
78 | success : function () {
79 | console.log('file opened successfully');
80 | }
81 | }
82 | );
83 | ```
84 |
85 | __Note on Electron:__ Do not forget to enable Node.js in your app by adding `"nodeIntegration": true` to `platforms/electron/platform_www/cdv-electron-settings.json` file, See [Cordova-Electron documentation](https://cordova.apache.org/docs/en/latest/guide/platforms/electron/index.html#customizing-the-application's-window-options).
86 |
87 | ### Market place installation
88 | 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:
89 |
90 | ```html
91 | Install from Google Play
92 | Install from App Store
93 | ```
94 | or in code:
95 |
96 | ```js
97 | window.open("[market:// or itms-apps:// link]","_system");
98 | ```
99 |
100 | ## fileOpener2.showOpenWithDialog(filePath, mimeType, options)
101 |
102 | Opens with system modal to open file with an already installed app.
103 |
104 | ### Supported Platforms
105 |
106 | - Android 5.1+
107 | - iOS 9+
108 |
109 | ### Quick Example
110 |
111 | ```js
112 | cordova.plugins.fileOpener2.showOpenWithDialog(
113 | '/Downloads/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Downloads/starwars.pdf
114 | 'application/pdf',
115 | {
116 | error : function(e) {
117 | console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
118 | },
119 | success : function () {
120 | console.log('file opened successfully');
121 | },
122 | position : [0, 0]
123 | }
124 | );
125 | ```
126 | `position` array of coordinates from top-left device screen, use for iOS dialog positioning.
127 |
128 | ## fileOpener2.uninstall(packageId, callbackContext)
129 |
130 | Uninstall a package with its ID.
131 |
132 | __Note__: You need to add `` to your `AndroidManifest.xml`
133 |
134 | ### Supported Platforms
135 |
136 | - Android 5.1+
137 |
138 | ### Quick Example
139 | ```js
140 | cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', {
141 | error : function(e) {
142 | console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
143 | },
144 | success : function() {
145 | console.log('Uninstall intent activity started.');
146 | }
147 | });
148 | ```
149 |
150 | ## fileOpener2.appIsInstalled(packageId, callbackContext)
151 |
152 | Check if an app is already installed.
153 |
154 | ### Supported Platforms
155 |
156 | - Android 5.1+
157 |
158 | ### Quick Example
159 | ```javascript
160 | cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', {
161 | success : function(res) {
162 | if (res.status === 0) {
163 | console.log('Adobe Reader is not installed.');
164 | } else {
165 | console.log('Adobe Reader is installed.')
166 | }
167 | }
168 | });
169 | ```
170 | ---
171 |
172 | ## Android APK installation limitation
173 |
174 | The following limitations apply when opening an APK file for installation:
175 | - 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:
176 | ```xml
177 |
178 |
179 |
180 |
181 |
182 | ```
183 |
184 | - 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.
185 |
186 | ---
187 |
188 | ## SD card limitation on Android
189 |
190 | It is not always possible to open a file from the SD Card using this plugin on Android. This is because the underlying Android library used [does not support serving files from secondary external storage devices](https://stackoverflow.com/questions/40318116/fileprovider-and-secondary-external-storage). Whether or not your the SD card is treated as a secondary external device depends on your particular phone's set up.
191 |
192 | ---
193 |
194 | ## Notes
195 |
196 | - 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.
197 |
198 | - [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`
199 |
200 | - 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)
201 |
202 |
203 | ---
204 |
205 |
206 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cordova-plugin-file-opener2",
3 | "version": "4.0.0",
4 | "description": "A File Opener Plugin for Cordova. (The Original Version)",
5 | "cordova": {
6 | "id": "cordova-plugin-file-opener2",
7 | "platforms": [
8 | "android",
9 | "ios",
10 | "windows",
11 | "electron"
12 | ]
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "https://github.com/pwlin/cordova-plugin-file-opener2.git"
17 | },
18 | "keywords": [
19 | "ecosystem:cordova",
20 | "cordova-android",
21 | "cordova-ios",
22 | "cordova-windows",
23 | "cordova-electron"
24 | ],
25 | "engines": {
26 | "cordovaDependencies": {
27 | "2.0.0": {
28 | "cordova": ">=6.0.0"
29 | },
30 | "3.0.0": {
31 | "cordova": ">=7.0.0"
32 | },
33 | "4.0.0": {
34 | "cordova-android": ">=10.0.0"
35 | }
36 | }
37 | },
38 | "author": {
39 | "name": "pwlin05@gmail.com"
40 | },
41 | "license": "MIT",
42 | "bugs": {
43 | "url": "https://github.com/pwlin/cordova-plugin-file-opener2/issues"
44 | },
45 | "homepage": "https://github.com/pwlin/cordova-plugin-file-opener2#readme"
46 | }
47 |
--------------------------------------------------------------------------------
/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | File Opener2
5 | A File Opener Plugin for Cordova. (The Original Version)
6 | MIT
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2013 pwlin - pwlin05@gmail.com
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | this software and associated documentation files (the "Software"), to deal in
8 | the Software without restriction, including without limitation the rights to
9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | the Software, and to permit persons to whom the Software is furnished to do so,
11 | subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | */
23 | package io.github.pwlin.cordova.plugins.fileopener2;
24 |
25 | import java.io.File;
26 | import java.util.List;
27 |
28 | import org.json.JSONArray;
29 | import org.json.JSONException;
30 | import org.json.JSONObject;
31 |
32 | import android.content.Context;
33 | import android.content.Intent;
34 | import android.content.pm.PackageManager;
35 | import android.content.pm.ResolveInfo;
36 | import android.net.Uri;
37 | import android.os.Build;
38 | import android.webkit.MimeTypeMap;
39 |
40 | import io.github.pwlin.cordova.plugins.fileopener2.FileProvider;
41 |
42 | import org.apache.cordova.CordovaPlugin;
43 | import org.apache.cordova.CallbackContext;
44 | import org.apache.cordova.PluginResult;
45 | import org.apache.cordova.CordovaResourceApi;
46 |
47 | public class FileOpener2 extends CordovaPlugin {
48 |
49 | /**
50 | * Executes the request and returns a boolean.
51 | *
52 | * @param action
53 | * The action to execute.
54 | * @param args
55 | * JSONArry of arguments for the plugin.
56 | * @param callbackContext
57 | * The callback context used when calling back into JavaScript.
58 | * @return boolean.
59 | */
60 | public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
61 | if (action.equals("open")) {
62 | String fileUrl = args.getString(0);
63 | String contentType = args.getString(1);
64 | Boolean openWithDefault = true;
65 | if(args.length() > 2){
66 | openWithDefault = args.getBoolean(2);
67 | }
68 | this._open(fileUrl, contentType, openWithDefault, callbackContext);
69 | }
70 | else if (action.equals("uninstall")) {
71 | this._uninstall(args.getString(0), callbackContext);
72 | }
73 | else if (action.equals("appIsInstalled")) {
74 | JSONObject successObj = new JSONObject();
75 | if (this._appIsInstalled(args.getString(0))) {
76 | successObj.put("status", PluginResult.Status.OK.ordinal());
77 | successObj.put("message", "Installed");
78 | }
79 | else {
80 | successObj.put("status", PluginResult.Status.NO_RESULT.ordinal());
81 | successObj.put("message", "Not installed");
82 | }
83 | callbackContext.success(successObj);
84 | }
85 | else {
86 | JSONObject errorObj = new JSONObject();
87 | errorObj.put("status", PluginResult.Status.INVALID_ACTION.ordinal());
88 | errorObj.put("message", "Invalid action");
89 | callbackContext.error(errorObj);
90 | }
91 | return true;
92 | }
93 |
94 | private void _open(String fileArg, String contentType, Boolean openWithDefault, CallbackContext callbackContext) throws JSONException {
95 | String fileName = "";
96 | try {
97 | CordovaResourceApi resourceApi = webView.getResourceApi();
98 | Uri fileUri = resourceApi.remapUri(Uri.parse(fileArg));
99 | fileName = fileUri.getPath();
100 | } catch (Exception e) {
101 | fileName = fileArg;
102 | }
103 | File file = new File(fileName);
104 | if (file.exists()) {
105 | try {
106 | if (contentType == null || contentType.trim().equals("")) {
107 | contentType = _getMimeType(fileName);
108 | }
109 |
110 | Intent intent;
111 | if (contentType.equals("application/vnd.android.package-archive")) {
112 | // https://stackoverflow.com/questions/9637629/can-we-install-an-apk-from-a-contentprovider/9672282#9672282
113 | intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
114 | Uri path;
115 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
116 | path = Uri.fromFile(file);
117 | } else {
118 | Context context = cordova.getActivity().getApplicationContext();
119 | path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".fileOpener2.provider", file);
120 | }
121 | intent.setDataAndType(path, contentType);
122 | intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
123 |
124 | } else {
125 | intent = new Intent(Intent.ACTION_VIEW);
126 | Context context = cordova.getActivity().getApplicationContext();
127 | Uri path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".fileOpener2.provider", file);
128 | intent.setDataAndType(path, contentType);
129 | intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
130 |
131 | }
132 |
133 | /*
134 | * @see
135 | * http://stackoverflow.com/questions/14321376/open-an-activity-from-a-cordovaplugin
136 | */
137 | if(openWithDefault){
138 | cordova.getActivity().startActivity(intent);
139 | }
140 | else{
141 | cordova.getActivity().startActivity(Intent.createChooser(intent, "Open File in..."));
142 | }
143 |
144 | callbackContext.success();
145 | } catch (android.content.ActivityNotFoundException e) {
146 | JSONObject errorObj = new JSONObject();
147 | errorObj.put("status", PluginResult.Status.ERROR.ordinal());
148 | errorObj.put("message", "Activity not found: " + e.getMessage());
149 | callbackContext.error(errorObj);
150 | }
151 | } else {
152 | JSONObject errorObj = new JSONObject();
153 | errorObj.put("status", PluginResult.Status.ERROR.ordinal());
154 | errorObj.put("message", "File not found");
155 | callbackContext.error(errorObj);
156 | }
157 | }
158 |
159 | private String _getMimeType(String url) {
160 | String mimeType = "*/*";
161 | int extensionIndex = url.lastIndexOf('.');
162 | if (extensionIndex > 0) {
163 | String extMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(url.substring(extensionIndex+1));
164 | if (extMimeType != null) {
165 | mimeType = extMimeType;
166 | }
167 | }
168 | return mimeType;
169 | }
170 |
171 | private void _uninstall(String packageId, CallbackContext callbackContext) throws JSONException {
172 | if (this._appIsInstalled(packageId)) {
173 | Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
174 | intent.setData(Uri.parse("package:" + packageId));
175 | cordova.getActivity().startActivity(intent);
176 | callbackContext.success();
177 | }
178 | else {
179 | JSONObject errorObj = new JSONObject();
180 | errorObj.put("status", PluginResult.Status.ERROR.ordinal());
181 | errorObj.put("message", "This package is not installed");
182 | callbackContext.error(errorObj);
183 | }
184 | }
185 |
186 | private boolean _appIsInstalled(String packageId) {
187 | PackageManager pm = cordova.getActivity().getPackageManager();
188 | boolean appInstalled = false;
189 | try {
190 | pm.getPackageInfo(packageId, PackageManager.GET_ACTIVITIES);
191 | appInstalled = true;
192 | } catch (PackageManager.NameNotFoundException e) {
193 | appInstalled = false;
194 | }
195 | return appInstalled;
196 | }
197 |
198 | }
199 |
200 |
--------------------------------------------------------------------------------
/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2013 pwlin - pwlin05@gmail.com
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | this software and associated documentation files (the "Software"), to deal in
8 | the Software without restriction, including without limitation the rights to
9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | the Software, and to permit persons to whom the Software is furnished to do so,
11 | subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | */
23 | package io.github.pwlin.cordova.plugins.fileopener2;
24 |
25 | /*
26 | * http://stackoverflow.com/questions/40746144/error-with-duplicated-fileprovider-in-manifest-xml-with-cordova/41550634#41550634
27 | */
28 | public class FileProvider extends androidx.core.content.FileProvider {
29 | }
30 |
--------------------------------------------------------------------------------
/src/android/res/xml/opener_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/browser/FileOpener2.js:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2019 fefc - fefc.dev@gmail.com
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | this software and associated documentation files (the "Software"), to deal in
8 | the Software without restriction, including without limitation the rights to
9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | the Software, and to permit persons to whom the Software is furnished to do so,
11 | subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | */
23 |
24 | const cacheDirectory = (require('./isChrome')()) ? 'filesystem:' + window.location.origin + '/temporary/' : 'file:///temporary/';
25 | const dataDirectory = (require('./isChrome')()) ? 'filesystem:' + window.location.origin + '/persistent/' : 'file:///persistent/';
26 |
27 | function open(successCallback, errorCallback, data) {
28 | var fullFilePath = data[0];
29 | //var contentType = data[1]; //Not needed in browser
30 | //var openDialog = data[2]; //Not needed in browser
31 |
32 | var dirPath = fullFilePath.substring(0, fullFilePath.lastIndexOf('/') + 1);
33 | var fileName = fullFilePath.substring(fullFilePath.lastIndexOf('/') + 1, fullFilePath.length);
34 | var fileSystemLocalPath = getLocalPathAndFileSystem(dirPath);
35 |
36 | if (!fileSystemLocalPath.error) {
37 | window.requestFileSystem(fileSystemLocalPath.fileSystem, 0, (fs) => {
38 | readFile(fs.root, fileSystemLocalPath.localPath + fileName).then((blob) => {
39 | FileSaver.saveAs(blob, fileName);
40 | successCallback();
41 | }).catch((error) => {
42 | errorCallback(error);
43 | });
44 | }, (error) => {
45 | errorCallback(error);
46 | });
47 | } else {
48 | errorCallback('INVALID_PATH');
49 | }
50 | }
51 |
52 | /**
53 | *
54 | * Gets the localPath according to the fileSystem (TEMPORARY or PERSISTENT).
55 | *
56 | * @param {String} Path to the file or directory to check
57 | * @returns {Object} value with informations to requestFileSystem later
58 | * @returns {string} value.localPath The localPath in relation with fileSystem.
59 | * @returns {number} value.fileSystem the fileSystem (TEMPORARY or PERSISTENT).
60 | * @returns {error} value.error if the path is not valid.
61 | * @returns {message} value.message error message.
62 | */
63 | function getLocalPathAndFileSystem(pathToCheck) {
64 | let ret = {
65 | localPath: '',
66 | fileSystem: window.TEMPORARY
67 | };
68 |
69 | if (pathToCheck.startsWith(cacheDirectory)) {
70 | ret.localPath = pathToCheck.replace(cacheDirectory, '');
71 | ret.fileSystem = window.TEMPORARY;
72 |
73 | } else if (pathToCheck.startsWith(dataDirectory)) {
74 | ret.localPath = pathToCheck.replace(dataDirectory, '');
75 | ret.fileSystem = window.PERSISTENT;
76 |
77 | } else {
78 | return {error: true, message: 'INVALID_PATH'};
79 | }
80 |
81 | if (!ret.localPath.endsWith('/')) ret.localPath += '/';
82 |
83 | return ret;
84 | }
85 |
86 | /**
87 | *
88 | * Reads a file in the fileSystem as an DataURL.
89 | *
90 | * @param {String} Root is the root folder of the fileSystem.
91 | * @param {String} Path is the file to be red.
92 | * @returns {Promise} which resolves with an Object containing DataURL, rejects if something went wrong.
93 | */
94 | function readFile(root, filePath) {
95 | return new Promise((resolve, reject) => {
96 | if (filePath.startsWith('/')) filePath = filePath.substring(1);
97 |
98 | root.getFile(filePath, {}, (fileEntry) => {
99 | fileEntry.file((file) => {
100 | let reader = new FileReader();
101 |
102 | reader.onload = function() {
103 | resolve(reader.result);
104 | };
105 |
106 | reader.onerror = function() {
107 | reject(reader.error);
108 | }
109 |
110 | reader.readAsDataURL(file);
111 |
112 | }, (error) => {
113 | reject(error);
114 | });
115 | }, (error) => {
116 | reject(error);
117 | });
118 | });
119 | }
120 |
121 | module.exports = {
122 | open: open
123 | };
124 |
125 | require( "cordova/exec/proxy" ).add( "FileOpener2", module.exports );
126 |
--------------------------------------------------------------------------------
/src/browser/FileSaver.min.js:
--------------------------------------------------------------------------------
1 | (function(a,b){if("function"==typeof define&&define.amd)define([],b);else if("undefined"!=typeof exports)b();else{b(),a.FileSaver={exports:{}}.exports}})(this,function(){"use strict";function b(a,b){return"undefined"==typeof b?b={autoBom:!1}:"object"!=typeof b&&(console.warn("Deprecated: Expected third argument to be a object"),b={autoBom:!b}),b.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(a.type)?new Blob(["\uFEFF",a],{type:a.type}):a}function c(b,c,d){var e=new XMLHttpRequest;e.open("GET",b),e.responseType="blob",e.onload=function(){a(e.response,c,d)},e.onerror=function(){console.error("could not download file")},e.send()}function d(a){var b=new XMLHttpRequest;b.open("HEAD",a,!1);try{b.send()}catch(a){}return 200<=b.status&&299>=b.status}function e(a){try{a.dispatchEvent(new MouseEvent("click"))}catch(c){var b=document.createEvent("MouseEvents");b.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),a.dispatchEvent(b)}}var f="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof global&&global.global===global?global:void 0,a=f.saveAs||("object"!=typeof window||window!==f?function(){}:"download"in HTMLAnchorElement.prototype?function(b,g,h){var i=f.URL||f.webkitURL,j=document.createElement("a");g=g||b.name||"download",j.download=g,j.rel="noopener","string"==typeof b?(j.href=b,j.origin===location.origin?e(j):d(j.href)?c(b,g,h):e(j,j.target="_blank")):(j.href=i.createObjectURL(b),setTimeout(function(){i.revokeObjectURL(j.href)},4E4),setTimeout(function(){e(j)},0))}:"msSaveOrOpenBlob"in navigator?function(f,g,h){if(g=g||f.name||"download","string"!=typeof f)navigator.msSaveOrOpenBlob(b(f,h),g);else if(d(f))c(f,g,h);else{var i=document.createElement("a");i.href=f,i.target="_blank",setTimeout(function(){e(i)})}}:function(a,b,d,e){if(e=e||open("","_blank"),e&&(e.document.title=e.document.body.innerText="downloading..."),"string"==typeof a)return c(a,b,d);var g="application/octet-stream"===a.type,h=/constructor/i.test(f.HTMLElement)||f.safari,i=/CriOS\/[\d]+/.test(navigator.userAgent);if((i||g&&h)&&"undefined"!=typeof FileReader){var j=new FileReader;j.onloadend=function(){var a=j.result;a=i?a:a.replace(/^data:[^;]*;/,"data:attachment/file;"),e?e.location.href=a:location=a,e=null},j.readAsDataURL(a)}else{var k=f.URL||f.webkitURL,l=k.createObjectURL(a);e?e.location=l:location.href=l,e=null,setTimeout(function(){k.revokeObjectURL(l)},4E4)}});f.saveAs=a.saveAs=a,"undefined"!=typeof module&&(module.exports=a)});
2 |
3 | //# sourceMappingURL=FileSaver.min.js.map
4 |
--------------------------------------------------------------------------------
/src/electron/FileOpener2.js:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2020 pwlin - pwlin05@gmail.com
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | this software and associated documentation files (the "Software"), to deal in
8 | the Software without restriction, including without limitation the rights to
9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | the Software, and to permit persons to whom the Software is furnished to do so,
11 | subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | */
23 | // https://www.electronjs.org/docs/api/shell
24 | const { shell } = global.require('electron');
25 | module.exports = {
26 | open: function (onSuccess, onError, fileName) {
27 | var opn = shell.openItem(fileName[0]);
28 | if (opn === true) {
29 | onSuccess(true);
30 | } else {
31 | onError({'status': 0, 'message': 'Failed opening file.'});
32 | }
33 | }
34 | };
35 | require('cordova/exec/proxy').add('FileOpener2', module.exports);
36 |
--------------------------------------------------------------------------------
/src/ios/FileOpener2.h:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2013 pwlin - pwlin05@gmail.com
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | this software and associated documentation files (the "Software"), to deal in
8 | the Software without restriction, including without limitation the rights to
9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | the Software, and to permit persons to whom the Software is furnished to do so,
11 | subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | */
23 |
24 | #import
25 |
26 | @interface FileOpener2 : CDVPlugin {
27 | NSString *localFile;
28 | }
29 |
30 | @property(nonatomic, strong) UIDocumentInteractionController *controller;
31 | @property(nonatomic, strong) CDVViewController *cdvViewController;
32 |
33 | - (void) open: (CDVInvokedUrlCommand*)command;
34 |
35 | @end
--------------------------------------------------------------------------------
/src/ios/FileOpener2.m:
--------------------------------------------------------------------------------
1 | /*
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2013 pwlin - pwlin05@gmail.com
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | this software and associated documentation files (the "Software"), to deal in
8 | the Software without restriction, including without limitation the rights to
9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | the Software, and to permit persons to whom the Software is furnished to do so,
11 | subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | */
23 | #import "FileOpener2.h"
24 | #import
25 |
26 | #import
27 | #import
28 |
29 | @implementation FileOpener2
30 | @synthesize controller = docController;
31 |
32 | CDVPluginResult* pluginResult = nil;
33 | NSString* callbackId = nil;
34 |
35 | - (void) open: (CDVInvokedUrlCommand*)command {
36 | callbackId = command.callbackId;
37 | NSString *path = [command.arguments objectAtIndex:0];
38 | NSString *contentType = [command.arguments objectAtIndex:1];
39 | BOOL showPreview = YES;
40 |
41 | if ([command.arguments count] >= 3) {
42 | showPreview = [[command.arguments objectAtIndex:2] boolValue];
43 | }
44 |
45 | CDVViewController* cont = (CDVViewController*)[super viewController];
46 | self.cdvViewController = cont;
47 | NSString *uti = nil;
48 |
49 | if ([contentType length] == 0) {
50 | NSArray *dotParts = [path componentsSeparatedByString:@"."];
51 | NSString *fileExt = [dotParts lastObject];
52 |
53 | uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL);
54 | } else {
55 | uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)contentType, NULL);
56 | }
57 |
58 | dispatch_async(dispatch_get_main_queue(), ^{
59 | NSURL *fileURL = NULL;
60 | NSString *decodedPath = [path stringByRemovingPercentEncoding];
61 |
62 | if ([path isEqualToString:decodedPath]) {
63 | NSLog(@"Path parameter not encoded. Building file URL encoding it...");
64 | fileURL = [NSURL fileURLWithPath:[path stringByReplacingOccurrencesOfString:@"file://" withString:@""]];;
65 | } else {
66 | NSLog(@"Path parameter already encoded. Building file URL without encoding it...");
67 | fileURL = [NSURL URLWithString:path];
68 | }
69 |
70 | localFile = fileURL.path;
71 |
72 | NSLog(@"looking for file at %@", fileURL);
73 | NSFileManager *fm = [NSFileManager defaultManager];
74 |
75 | if (![fm fileExistsAtPath:localFile]) {
76 | NSDictionary *jsonObj = @{@"status" : @"9",
77 | @"message" : @"File does not exist"};
78 | CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj];
79 | [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
80 | return;
81 | }
82 |
83 | docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
84 | docController.delegate = self;
85 | docController.UTI = uti;
86 |
87 | //Opens the file preview
88 | CGRect rect;
89 |
90 | if ([command.arguments count] >= 4) {
91 | NSArray *positionValues = [command.arguments objectAtIndex:3];
92 |
93 | if (![positionValues isEqual:[NSNull null]] && [positionValues count] >= 2) {
94 | rect = CGRectMake(0, 0, [[positionValues objectAtIndex:0] floatValue], [[positionValues objectAtIndex:1] floatValue]);
95 | } else {
96 | rect = CGRectMake(0, 0, 0, 0);
97 | }
98 | } else {
99 | rect = CGRectMake(0, 0, cont.view.bounds.size.width, cont.view.bounds.size.height);
100 | }
101 |
102 | BOOL wasOpened = NO;
103 |
104 | if (showPreview) {
105 | wasOpened = [docController presentPreviewAnimated: NO];
106 | } else {
107 | CDVViewController* cont = self.cdvViewController;
108 | wasOpened = [docController presentOpenInMenuFromRect:rect inView:cont.view animated:YES];
109 | }
110 |
111 | if (wasOpened) {
112 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @""];
113 | } else {
114 | NSDictionary *jsonObj = [ [NSDictionary alloc]
115 | initWithObjectsAndKeys :
116 | @"9", @"status",
117 | @"Could not handle UTI", @"message",
118 | nil
119 | ];
120 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj];
121 | [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
122 | }
123 | });
124 | }
125 |
126 | @end
127 |
128 | @implementation FileOpener2 (UIDocumentInteractionControllerDelegate)
129 | - (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller {
130 | [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
131 | }
132 |
133 | - (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller {
134 | [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
135 | }
136 |
137 | - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
138 | UIViewController *presentingViewController = self.viewController;
139 |
140 | if (presentingViewController.view.window != [UIApplication sharedApplication].keyWindow) {
141 | presentingViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
142 | }
143 |
144 | while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]) {
145 | presentingViewController = presentingViewController.presentedViewController;
146 | }
147 |
148 | return presentingViewController;
149 | }
150 |
151 | @end
152 |
--------------------------------------------------------------------------------
/src/windows/fileOpener2Proxy.js:
--------------------------------------------------------------------------------
1 |
2 | var cordova = require('cordova'),
3 | fileOpener2 = require('./FileOpener2');
4 |
5 | var schemes = [
6 | { protocol: 'ms-app', getFile: getFileFromApplicationUri },
7 | { protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile
8 | ]
9 |
10 | function nthIndex(str, pat, n) {
11 | var L = str.length, i = -1;
12 | while (n-- && i++ < L) {
13 | i = str.indexOf(pat, i);
14 | if (i < 0) break;
15 | }
16 | return i;
17 | }
18 |
19 | function getFileFromApplicationUri(uri) {
20 | /* bad path from a file entry due to the last '//'
21 | example: ms-appdata:///local//path/to/file
22 | */
23 | var index = nthIndex(uri, "//", 3);
24 | var newUri = uri.substr(0, index) + uri.substr(index + 1);
25 |
26 | var applicationUri = new Windows.Foundation.Uri(newUri);
27 |
28 | return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri);
29 | }
30 |
31 | function getFileFromFileUri(uri) {
32 | /* uri example:
33 | cdvfile://localhost/persistent|temporary|another-fs-root/path/to/file
34 | */
35 | var indexFrom = nthIndex(uri, "/", 3) + 1;
36 | var indexTo = nthIndex(uri, "/", 4);
37 | var whichFolder = uri.substring(indexFrom, indexTo);
38 | var filePath = uri.substr(indexTo + 1);
39 | var path = "\\" + filePath;
40 |
41 | if (whichFolder == "persistent") {
42 | path = Windows.Storage.ApplicationData.current.localFolder.path + path;
43 | }
44 | else { //temporary, note: no roaming management
45 | path = Windows.Storage.ApplicationData.current.temporaryFolder.path + path;
46 | }
47 |
48 | return getFileFromNativePath(path);
49 | }
50 |
51 | function getFileFromNativePath(path) {
52 | var nativePath = path.split("/").join("\\");
53 |
54 | return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath);
55 | }
56 |
57 | function getFileLoaderForScheme(path) {
58 | var fileLoader = getFileFromNativePath;
59 |
60 | schemes.some(function (scheme) {
61 | return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false;
62 | });
63 |
64 | return fileLoader;
65 | }
66 |
67 | module.exports = {
68 |
69 | open: function (successCallback, errorCallback, args) {
70 |
71 | var path = args[0];
72 |
73 | var getFile = getFileLoaderForScheme(path);
74 |
75 | getFile(path).then(function (file) {
76 | var options = new Windows.System.LauncherOptions();
77 |
78 | try{
79 | Windows.System.Launcher.launchFileAsync(file, options).then(function (success) {
80 | successCallback();
81 | }, function (error) {
82 | errorCallback(error);
83 | });
84 | }catch(error){
85 | errorCallback(error);
86 | }
87 |
88 | }, function (error) {
89 | console.log("Error while opening the file: "+error);
90 | errorCallback(error);
91 | });
92 | }
93 |
94 | };
95 |
96 | require("cordova/exec/proxy").add("FileOpener2", module.exports);
97 |
98 |
--------------------------------------------------------------------------------
/www/browser/isChrome.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | module.exports = function () {
23 | // window.webkitRequestFileSystem and window.webkitResolveLocalFileSystemURL are available only in Chrome and
24 | // possibly a good flag to indicate that we're running in Chrome
25 | return window.webkitRequestFileSystem && window.webkitResolveLocalFileSystemURL;
26 | };
27 |
--------------------------------------------------------------------------------
/www/plugins.FileOpener2.js:
--------------------------------------------------------------------------------
1 | /*jslint browser: true, devel: true, node: true, sloppy: true, plusplus: true*/
2 | /*global require, cordova */
3 | /*
4 | The MIT License (MIT)
5 |
6 | Copyright (c) 2013 pwlin - pwlin05@gmail.com
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy of
9 | this software and associated documentation files (the "Software"), to deal in
10 | the Software without restriction, including without limitation the rights to
11 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12 | the Software, and to permit persons to whom the Software is furnished to do so,
13 | subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in all
16 | copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 | var exec = require('cordova/exec');
26 |
27 | function FileOpener2() {}
28 |
29 | FileOpener2.prototype.open = function (fileName, contentType, callbackContext) {
30 | contentType = contentType || '';
31 | callbackContext = callbackContext || {};
32 | exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType]);
33 | };
34 |
35 | FileOpener2.prototype.showOpenWithDialog = function (fileName, contentType, callbackContext) {
36 | contentType = contentType || '';
37 | callbackContext = callbackContext || {};
38 | exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, false, callbackContext.position || [0, 0]]);
39 | };
40 |
41 | FileOpener2.prototype.uninstall = function (packageId, callbackContext) {
42 | callbackContext = callbackContext || {};
43 | exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'uninstall', [packageId]);
44 | };
45 |
46 | FileOpener2.prototype.appIsInstalled = function (packageId, callbackContext) {
47 | callbackContext = callbackContext || {};
48 | exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'appIsInstalled', [packageId]);
49 | };
50 |
51 | module.exports = new FileOpener2();
52 |
--------------------------------------------------------------------------------