community-cordova-plugin-filepath 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +3 -0
- package/CHANGELOG.md +43 -0
- package/LICENSE.md +202 -0
- package/README.md +47 -0
- package/package.json +28 -0
- package/plugin.xml +54 -0
- package/src/android/FilePath.java +512 -0
- package/www/FilePath.js +14 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# 1.6.0
|
|
2
|
+
|
|
3
|
+
* [#70](https://github.com/hiddentao/cordova-plugin-filepath/pull/70)
|
|
4
|
+
* [#71](https://github.com/hiddentao/cordova-plugin-filepath/pull/71)
|
|
5
|
+
|
|
6
|
+
# 1.5.8
|
|
7
|
+
|
|
8
|
+
* Added "no longer actively maintained" message to README
|
|
9
|
+
|
|
10
|
+
# 1.5.7
|
|
11
|
+
|
|
12
|
+
* [Fixes issue #60](https://github.com/hiddentao/cordova-plugin-filepath/issues/60)
|
|
13
|
+
|
|
14
|
+
# 1.5.6
|
|
15
|
+
|
|
16
|
+
* [Fixes issue #50](https://github.com/hiddentao/cordova-plugin-filepath/issues/50)
|
|
17
|
+
|
|
18
|
+
# 1.5.5
|
|
19
|
+
|
|
20
|
+
* [Remove unneeded permission](https://github.com/hiddentao/cordova-plugin-filepath/pull/51)
|
|
21
|
+
|
|
22
|
+
# 1.5.4
|
|
23
|
+
|
|
24
|
+
* [Remove unneeded permission](https://github.com/hiddentao/cordova-plugin-filepath/pull/42)
|
|
25
|
+
|
|
26
|
+
# 1.0.2
|
|
27
|
+
|
|
28
|
+
Release notes:
|
|
29
|
+
|
|
30
|
+
* [da0e1c6](https://github.com/hiddentao/cordova-plugin-filepath/commit/da0e1c68e422caac9c196e41d2580460a6da6d67): Rename plugin to ``cordova-plugin-filepath``
|
|
31
|
+
|
|
32
|
+
# 1.0.1
|
|
33
|
+
|
|
34
|
+
Merged PR#4 ([e571105](https://github.com/hiddentao/cordova-plugin-filepath/commit/e571105e0ffa2bfa09b27a13613778755e017961)) with the following changes:
|
|
35
|
+
|
|
36
|
+
* Added detection for Google Drive content uri. Better error description.
|
|
37
|
+
* Fix resolving native path from external storage.
|
|
38
|
+
* Fix resolving native path from Google Photos. Append "file://" to final result
|
|
39
|
+
* Added new uri authority for Google Photos
|
|
40
|
+
|
|
41
|
+
# 1.0.0
|
|
42
|
+
|
|
43
|
+
Initial version.
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2015 [Ramesh Nair](https://hiddentao.com)
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/community-cordova-plugin-filepath)
|
|
2
|
+
[](https://www.npmjs.com/package/community-cordova-plugin-filepath)
|
|
3
|
+
|
|
4
|
+
#### This is a fork of the original plugin cordova-plugin-filepath
|
|
5
|
+
|
|
6
|
+
# community-cordova-plugin-filepath
|
|
7
|
+
|
|
8
|
+
This plugin allows you to resolve the native filesystem path for Android content
|
|
9
|
+
URIs and is based on code in the [aFileChooser](https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java) library.
|
|
10
|
+
|
|
11
|
+
Original inspiration [from StackOverflow](http://stackoverflow.com/questions/20067508/get-real-path-from-uri-android-kitkat-new-storage-access-framework).
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
$ cordova plugin add community-cordova-plugin-filepath
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Supported Platforms
|
|
20
|
+
|
|
21
|
+
* Android
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Once installed the plugin defines the `window.FilePath` object. To resolve a
|
|
26
|
+
file path:
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
window.FilePath.resolveNativePath('content://...', successCallback, errorCallback);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
##### successCallback
|
|
33
|
+
Returns the ``file://`` file path.
|
|
34
|
+
|
|
35
|
+
##### errorCallback
|
|
36
|
+
Returns the following object:
|
|
37
|
+
```js
|
|
38
|
+
{ code: <integer>, message: <string> }
|
|
39
|
+
```
|
|
40
|
+
Possible error codes are:
|
|
41
|
+
* ``-1`` - describes an invalid action
|
|
42
|
+
* ``0`` - ``file://`` path could not be resolved
|
|
43
|
+
* ``1`` - the native path links to a cloud file (e.g: from Google Drive app)
|
|
44
|
+
|
|
45
|
+
## LICENSE
|
|
46
|
+
|
|
47
|
+
Apache (see LICENSE.md)
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "community-cordova-plugin-filepath",
|
|
3
|
+
"version": "1.7.0",
|
|
4
|
+
"description": "Resolve native file paths from content URLs for Cordova platforms",
|
|
5
|
+
"cordova": {
|
|
6
|
+
"id": "community-cordova-plugin-filepath",
|
|
7
|
+
"platforms": [
|
|
8
|
+
"android"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"version": "sync-cordova-xml package.json plugin.xml --output plugin.xml && git add plugin.xml"
|
|
13
|
+
},
|
|
14
|
+
"repository": "EYALIN/community-cordova-plugin-filepath/tree/master",
|
|
15
|
+
"homepage": "https://github.com/EYALIN/community-cordova-plugin-filepath/tree/master",
|
|
16
|
+
"funding": "https://github.com/sponsors/EYALIN",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"cordova",
|
|
19
|
+
"file",
|
|
20
|
+
"ecosystem:cordova",
|
|
21
|
+
"cordova-android"
|
|
22
|
+
],
|
|
23
|
+
"author": "Ramesh Nair <ram@hiddentao.com>",
|
|
24
|
+
"license": "Apache 2.0",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"sync-cordova-xml": "^0.4.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/plugin.xml
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
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
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
Unless required by applicable law or agreed to in writing,
|
|
12
|
+
software distributed under the License is distributed on an
|
|
13
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
KIND, either express or implied. See the License for the
|
|
15
|
+
specific language governing permissions and limitations
|
|
16
|
+
under the License.
|
|
17
|
+
-->
|
|
18
|
+
|
|
19
|
+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
20
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
21
|
+
id="community-cordova-plugin-filepath" version="1.7.0">
|
|
22
|
+
<name>community-cordova-plugin-filepath</name>
|
|
23
|
+
<description>Resolve native file paths from content URLs for Cordova platforms</description>
|
|
24
|
+
<license>Apache 2.0</license>
|
|
25
|
+
<keywords>cordova,file,ecosystem:cordova,cordova-android</keywords>
|
|
26
|
+
<repo>https://github.com/hiddentao/cordova-plugin-filepath.git</repo>
|
|
27
|
+
<issue>https://github.com/hiddentao/cordova-plugin-filepath/issues</issue>
|
|
28
|
+
|
|
29
|
+
<engines>
|
|
30
|
+
<engine name="cordova-android" version=">=3.1.0"/><!-- Uses CordovaResourceApi -->
|
|
31
|
+
</engines>
|
|
32
|
+
|
|
33
|
+
<!-- android -->
|
|
34
|
+
<platform name="android">
|
|
35
|
+
<framework src="commons-io:commons-io:2.4" />
|
|
36
|
+
<js-module src="www/FilePath.js" name="FilePath">
|
|
37
|
+
<clobbers target="window.FilePath"/>
|
|
38
|
+
</js-module>
|
|
39
|
+
|
|
40
|
+
<config-file target="res/xml/config.xml" parent="/*">
|
|
41
|
+
<feature name="FilePath">
|
|
42
|
+
<param name="android-package" value="com.hiddentao.cordova.filepath.FilePath"/>
|
|
43
|
+
<param name="onload" value="true"/>
|
|
44
|
+
</feature>
|
|
45
|
+
</config-file>
|
|
46
|
+
|
|
47
|
+
<config-file target="AndroidManifest.xml" parent="/*">
|
|
48
|
+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
|
49
|
+
</config-file>
|
|
50
|
+
|
|
51
|
+
<source-file src="src/android/FilePath.java" target-dir="src/com/hiddentao/cordova/filepath"/>
|
|
52
|
+
</platform>
|
|
53
|
+
<author email="ram@hiddentao.com">Ramesh Nair</author>
|
|
54
|
+
</plugin>
|
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
package com.hiddentao.cordova.filepath;
|
|
2
|
+
|
|
3
|
+
import android.text.TextUtils;
|
|
4
|
+
import android.Manifest;
|
|
5
|
+
import android.content.ContentUris;
|
|
6
|
+
import android.content.Context;
|
|
7
|
+
import android.content.pm.PackageManager;
|
|
8
|
+
import android.net.Uri;
|
|
9
|
+
import android.provider.OpenableColumns;
|
|
10
|
+
import android.util.Log;
|
|
11
|
+
import android.database.Cursor;
|
|
12
|
+
import android.os.Build;
|
|
13
|
+
import android.os.Environment;
|
|
14
|
+
import android.provider.DocumentsContract;
|
|
15
|
+
import android.provider.MediaStore;
|
|
16
|
+
import android.support.v4.app.ActivityCompat;
|
|
17
|
+
|
|
18
|
+
import org.apache.cordova.CallbackContext;
|
|
19
|
+
import org.apache.cordova.CordovaInterface;
|
|
20
|
+
import org.apache.cordova.CordovaPlugin;
|
|
21
|
+
import org.apache.cordova.CordovaWebView;
|
|
22
|
+
import org.apache.cordova.PermissionHelper;
|
|
23
|
+
import org.json.JSONArray;
|
|
24
|
+
import org.json.JSONObject;
|
|
25
|
+
import org.json.JSONException;
|
|
26
|
+
|
|
27
|
+
import java.io.FileOutputStream;
|
|
28
|
+
import java.io.InputStream;
|
|
29
|
+
import java.util.List;
|
|
30
|
+
import java.io.File;
|
|
31
|
+
|
|
32
|
+
import java.io.IOException;
|
|
33
|
+
import java.io.OutputStream;
|
|
34
|
+
|
|
35
|
+
import android.content.pm.ApplicationInfo;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
import org.apache.commons.io.IOUtils;
|
|
39
|
+
|
|
40
|
+
public class FilePath extends CordovaPlugin {
|
|
41
|
+
|
|
42
|
+
private static final String TAG = "[FilePath plugin]: ";
|
|
43
|
+
|
|
44
|
+
private static final int INVALID_ACTION_ERROR_CODE = -1;
|
|
45
|
+
|
|
46
|
+
private static final int GET_PATH_ERROR_CODE = 0;
|
|
47
|
+
private static final String GET_PATH_ERROR_ID = null;
|
|
48
|
+
|
|
49
|
+
private static final int GET_CLOUD_PATH_ERROR_CODE = 1;
|
|
50
|
+
private static final String GET_CLOUD_PATH_ERROR_ID = "cloud";
|
|
51
|
+
|
|
52
|
+
private static final int RC_READ_EXTERNAL_STORAGE = 5;
|
|
53
|
+
|
|
54
|
+
private static CallbackContext callback;
|
|
55
|
+
private static String uriStr;
|
|
56
|
+
|
|
57
|
+
public static final int READ_REQ_CODE = 0;
|
|
58
|
+
|
|
59
|
+
public static final String READ = Manifest.permission.READ_EXTERNAL_STORAGE;
|
|
60
|
+
|
|
61
|
+
protected void getReadPermission(int requestCode) {
|
|
62
|
+
PermissionHelper.requestPermission(this, requestCode, READ);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public void initialize(CordovaInterface cordova, final CordovaWebView webView) {
|
|
66
|
+
super.initialize(cordova, webView);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Executes the request and returns PluginResult.
|
|
71
|
+
*
|
|
72
|
+
* @param action The action to execute.
|
|
73
|
+
* @param args JSONArry of arguments for the plugin.
|
|
74
|
+
* @param callbackContext The callback context through which to return stuff to caller.
|
|
75
|
+
* @return A PluginResult object with a status and message.
|
|
76
|
+
*/
|
|
77
|
+
@Override
|
|
78
|
+
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
|
79
|
+
this.callback = callbackContext;
|
|
80
|
+
this.uriStr = args.getString(0);
|
|
81
|
+
if (action.equals("resolveNativePath")) {
|
|
82
|
+
if (PermissionHelper.hasPermission(this, READ)) {
|
|
83
|
+
resolveNativePath();
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
getReadPermission(READ_REQ_CODE);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
JSONObject resultObj = new JSONObject();
|
|
93
|
+
|
|
94
|
+
resultObj.put("code", INVALID_ACTION_ERROR_CODE);
|
|
95
|
+
resultObj.put("message", "Invalid action.");
|
|
96
|
+
|
|
97
|
+
callbackContext.error(resultObj);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public void resolveNativePath() throws JSONException {
|
|
104
|
+
JSONObject resultObj = new JSONObject();
|
|
105
|
+
/* content:///... */
|
|
106
|
+
Uri pvUrl = Uri.parse(this.uriStr);
|
|
107
|
+
Log.d(TAG, "URI: " + this.uriStr);
|
|
108
|
+
|
|
109
|
+
Context appContext = this.cordova.getActivity().getApplicationContext();
|
|
110
|
+
|
|
111
|
+
//String filePath = getPath(appContext, pvUrl);
|
|
112
|
+
String filePath = getFilePathFromURI(appContext, pvUrl);
|
|
113
|
+
//check result; send error/success callback
|
|
114
|
+
if (filePath == GET_PATH_ERROR_ID) {
|
|
115
|
+
resultObj.put("code", GET_PATH_ERROR_CODE);
|
|
116
|
+
resultObj.put("message", "Unable to resolve filesystem path.");
|
|
117
|
+
|
|
118
|
+
this.callback.error(resultObj);
|
|
119
|
+
}
|
|
120
|
+
else if (filePath.equals(GET_CLOUD_PATH_ERROR_ID)) {
|
|
121
|
+
resultObj.put("code", GET_CLOUD_PATH_ERROR_CODE);
|
|
122
|
+
resultObj.put("message", "Files from cloud cannot be resolved to filesystem, download is required.");
|
|
123
|
+
|
|
124
|
+
this.callback.error(resultObj);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
Log.d(TAG, "Filepath: " + filePath);
|
|
128
|
+
|
|
129
|
+
this.callback.success("file://" + filePath);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public static String getFilePathFromURI(Context context, Uri contentUri) {
|
|
134
|
+
//copy file and send new file path
|
|
135
|
+
String fileName = getFileName(contentUri);
|
|
136
|
+
if (!TextUtils.isEmpty(fileName)) {
|
|
137
|
+
File folder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getPath() +
|
|
138
|
+
File.separator + getApplicationName(context));
|
|
139
|
+
|
|
140
|
+
boolean success = true;
|
|
141
|
+
|
|
142
|
+
if (!folder.exists()) {
|
|
143
|
+
success = folder.mkdirs();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (success) {
|
|
147
|
+
File copyFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getPath() +
|
|
148
|
+
File.separator + getApplicationName(context) + File.separator + fileName);
|
|
149
|
+
copy(context, contentUri, copyFile);
|
|
150
|
+
return copyFile.getAbsolutePath();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public static String getFileName(Uri uri) {
|
|
158
|
+
if (uri == null) return null;
|
|
159
|
+
String fileName = null;
|
|
160
|
+
String path = uri.getPath();
|
|
161
|
+
int cut = path.lastIndexOf('/');
|
|
162
|
+
if (cut != -1) {
|
|
163
|
+
fileName = path.substring(cut + 1);
|
|
164
|
+
}
|
|
165
|
+
return fileName;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public static void copy(Context context, Uri srcUri, File dstFile) {
|
|
169
|
+
try {
|
|
170
|
+
InputStream inputStream = context.getContentResolver().openInputStream(srcUri);
|
|
171
|
+
if (inputStream == null) return;
|
|
172
|
+
OutputStream outputStream = new FileOutputStream(dstFile);
|
|
173
|
+
IOUtils.copy(inputStream, outputStream);
|
|
174
|
+
inputStream.close();
|
|
175
|
+
outputStream.close();
|
|
176
|
+
} catch (IOException e) {
|
|
177
|
+
e.printStackTrace();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
public static String getApplicationName(Context context) {
|
|
182
|
+
ApplicationInfo applicationInfo = context.getApplicationInfo();
|
|
183
|
+
int stringId = applicationInfo.labelRes;
|
|
184
|
+
return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : context.getString(stringId);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException {
|
|
188
|
+
for (int r:grantResults) {
|
|
189
|
+
if (r == PackageManager.PERMISSION_DENIED) {
|
|
190
|
+
JSONObject resultObj = new JSONObject();
|
|
191
|
+
resultObj.put("code", 3);
|
|
192
|
+
resultObj.put("message", "Filesystem permission was denied.");
|
|
193
|
+
|
|
194
|
+
this.callback.error(resultObj);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (requestCode == READ_REQ_CODE) {
|
|
200
|
+
resolveNativePath();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @param uri The Uri to check.
|
|
207
|
+
* @return Whether the Uri authority is ExternalStorageProvider.
|
|
208
|
+
*/
|
|
209
|
+
private static boolean isExternalStorageDocument(Uri uri) {
|
|
210
|
+
return "com.android.externalstorage.documents".equals(uri.getAuthority());
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @param uri The Uri to check.
|
|
215
|
+
* @return Whether the Uri authority is DownloadsProvider.
|
|
216
|
+
*/
|
|
217
|
+
private static boolean isDownloadsDocument(Uri uri) {
|
|
218
|
+
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @param uri The Uri to check.
|
|
223
|
+
* @return Whether the Uri authority is MediaProvider.
|
|
224
|
+
*/
|
|
225
|
+
private static boolean isMediaDocument(Uri uri) {
|
|
226
|
+
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @param uri The Uri to check.
|
|
231
|
+
* @return Whether the Uri authority is Google Photos.
|
|
232
|
+
*/
|
|
233
|
+
private static boolean isGooglePhotosUri(Uri uri) {
|
|
234
|
+
return ("com.google.android.apps.photos.content".equals(uri.getAuthority())
|
|
235
|
+
|| "com.google.android.apps.photos.contentprovider".equals(uri.getAuthority()));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @param uri The Uri to check.
|
|
240
|
+
* @return Whether the Uri authority is Google Drive.
|
|
241
|
+
*/
|
|
242
|
+
private static boolean isGoogleDriveUri(Uri uri) {
|
|
243
|
+
return "com.google.android.apps.docs.storage".equals(uri.getAuthority()) || "com.google.android.apps.docs.storage.legacy".equals(uri.getAuthority());
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Get the value of the data column for this Uri. This is useful for
|
|
248
|
+
* MediaStore Uris, and other file-based ContentProviders.
|
|
249
|
+
*
|
|
250
|
+
* @param context The context.
|
|
251
|
+
* @param uri The Uri to query.
|
|
252
|
+
* @param selection (Optional) Filter used in the query.
|
|
253
|
+
* @param selectionArgs (Optional) Selection arguments used in the query.
|
|
254
|
+
* @return The value of the _data column, which is typically a file path.
|
|
255
|
+
*/
|
|
256
|
+
private static String getDataColumn(Context context, Uri uri, String selection,
|
|
257
|
+
String[] selectionArgs) {
|
|
258
|
+
|
|
259
|
+
Cursor cursor = null;
|
|
260
|
+
final String column = "_data";
|
|
261
|
+
final String[] projection = {
|
|
262
|
+
column
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
try {
|
|
266
|
+
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
|
|
267
|
+
null);
|
|
268
|
+
if (cursor != null && cursor.moveToFirst()) {
|
|
269
|
+
final int column_index = cursor.getColumnIndexOrThrow(column);
|
|
270
|
+
return cursor.getString(column_index);
|
|
271
|
+
}
|
|
272
|
+
} finally {
|
|
273
|
+
if (cursor != null)
|
|
274
|
+
cursor.close();
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Get content:// from segment list
|
|
281
|
+
* In the new Uri Authority of Google Photos, the last segment is not the content:// anymore
|
|
282
|
+
* So let's iterate through all segments and find the content uri!
|
|
283
|
+
*
|
|
284
|
+
* @param segments The list of segment
|
|
285
|
+
*/
|
|
286
|
+
private static String getContentFromSegments(List<String> segments) {
|
|
287
|
+
String contentPath = "";
|
|
288
|
+
|
|
289
|
+
for(String item : segments) {
|
|
290
|
+
if (item.startsWith("content://")) {
|
|
291
|
+
contentPath = item;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return contentPath;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Check if a file exists on device
|
|
301
|
+
*
|
|
302
|
+
* @param filePath The absolute file path
|
|
303
|
+
*/
|
|
304
|
+
private static boolean fileExists(String filePath) {
|
|
305
|
+
File file = new File(filePath);
|
|
306
|
+
|
|
307
|
+
return file.exists();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Get full file path from external storage
|
|
312
|
+
*
|
|
313
|
+
* @param pathData The storage type and the relative path
|
|
314
|
+
*/
|
|
315
|
+
private static String getPathFromExtSD(String[] pathData) {
|
|
316
|
+
final String type = pathData[0];
|
|
317
|
+
final String relativePath = "/" + pathData[1];
|
|
318
|
+
String fullPath = "";
|
|
319
|
+
|
|
320
|
+
// on my Sony devices (4.4.4 & 5.1.1), `type` is a dynamic string
|
|
321
|
+
// something like "71F8-2C0A", some kind of unique id per storage
|
|
322
|
+
// don't know any API that can get the root path of that storage based on its id.
|
|
323
|
+
//
|
|
324
|
+
// so no "primary" type, but let the check here for other devices
|
|
325
|
+
if ("primary".equalsIgnoreCase(type)) {
|
|
326
|
+
fullPath = Environment.getExternalStorageDirectory() + relativePath;
|
|
327
|
+
if (fileExists(fullPath)) {
|
|
328
|
+
return fullPath;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Environment.isExternalStorageRemovable() is `true` for external and internal storage
|
|
333
|
+
// so we cannot relay on it.
|
|
334
|
+
//
|
|
335
|
+
// instead, for each possible path, check if file exists
|
|
336
|
+
// we'll start with secondary storage as this could be our (physically) removable sd card
|
|
337
|
+
fullPath = System.getenv("SECONDARY_STORAGE") + relativePath;
|
|
338
|
+
if (fileExists(fullPath)) {
|
|
339
|
+
return fullPath;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
fullPath = System.getenv("EXTERNAL_STORAGE") + relativePath;
|
|
343
|
+
if (fileExists(fullPath)) {
|
|
344
|
+
return fullPath;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return fullPath;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Get a file path from a Uri. This will get the the path for Storage Access
|
|
352
|
+
* Framework Documents, as well as the _data field for the MediaStore and
|
|
353
|
+
* other file-based ContentProviders.<br>
|
|
354
|
+
* <br>
|
|
355
|
+
* Callers should check whether the path is local before assuming it
|
|
356
|
+
* represents a local file.
|
|
357
|
+
*
|
|
358
|
+
* @param context The context.
|
|
359
|
+
* @param uri The Uri to query.
|
|
360
|
+
*/
|
|
361
|
+
private static String getPath(final Context context, final Uri uri) {
|
|
362
|
+
|
|
363
|
+
Log.d(TAG, "File - " +
|
|
364
|
+
"Authority: " + uri.getAuthority() +
|
|
365
|
+
", Fragment: " + uri.getFragment() +
|
|
366
|
+
", Port: " + uri.getPort() +
|
|
367
|
+
", Query: " + uri.getQuery() +
|
|
368
|
+
", Scheme: " + uri.getScheme() +
|
|
369
|
+
", Host: " + uri.getHost() +
|
|
370
|
+
", Segments: " + uri.getPathSegments().toString()
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
|
374
|
+
|
|
375
|
+
// DocumentProvider
|
|
376
|
+
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
|
|
377
|
+
// ExternalStorageProvider
|
|
378
|
+
if (isExternalStorageDocument(uri)) {
|
|
379
|
+
final String docId = DocumentsContract.getDocumentId(uri);
|
|
380
|
+
final String[] split = docId.split(":");
|
|
381
|
+
final String type = split[0];
|
|
382
|
+
|
|
383
|
+
String fullPath = getPathFromExtSD(split);
|
|
384
|
+
if (fullPath != "") {
|
|
385
|
+
return fullPath;
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
// DownloadsProvider
|
|
392
|
+
else if (isDownloadsDocument(uri)) {
|
|
393
|
+
// thanks to https://github.com/hiddentao/cordova-plugin-filepath/issues/34#issuecomment-430129959
|
|
394
|
+
Cursor cursor = null;
|
|
395
|
+
try {
|
|
396
|
+
cursor = context.getContentResolver().query(uri, new String[]{MediaStore.MediaColumns.DISPLAY_NAME}, null, null, null);
|
|
397
|
+
if (cursor != null && cursor.moveToFirst()) {
|
|
398
|
+
String fileName = cursor.getString(0);
|
|
399
|
+
String path = Environment.getExternalStorageDirectory().toString() + "/Download/" + fileName;
|
|
400
|
+
if (!TextUtils.isEmpty(path)) {
|
|
401
|
+
return path;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
} finally {
|
|
405
|
+
if (cursor != null)
|
|
406
|
+
cursor.close();
|
|
407
|
+
}
|
|
408
|
+
//
|
|
409
|
+
final String id = DocumentsContract.getDocumentId(uri);
|
|
410
|
+
try {
|
|
411
|
+
final Uri contentUri = ContentUris.withAppendedId(
|
|
412
|
+
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
|
413
|
+
|
|
414
|
+
return getDataColumn(context, contentUri, null, null);
|
|
415
|
+
} catch(NumberFormatException e) {
|
|
416
|
+
//In Android 8 and Android P the id is not a number
|
|
417
|
+
return uri.getPath().replaceFirst("^/document/raw:", "").replaceFirst("^raw:", "");
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
// MediaProvider
|
|
421
|
+
else if (isMediaDocument(uri)) {
|
|
422
|
+
final String docId = DocumentsContract.getDocumentId(uri);
|
|
423
|
+
final String[] split = docId.split(":");
|
|
424
|
+
final String type = split[0];
|
|
425
|
+
|
|
426
|
+
Uri contentUri = null;
|
|
427
|
+
if ("image".equals(type)) {
|
|
428
|
+
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
|
429
|
+
} else if ("video".equals(type)) {
|
|
430
|
+
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
|
431
|
+
} else if ("audio".equals(type)) {
|
|
432
|
+
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
final String selection = "_id=?";
|
|
436
|
+
final String[] selectionArgs = new String[] {
|
|
437
|
+
split[1]
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
return getDataColumn(context, contentUri, selection, selectionArgs);
|
|
441
|
+
}
|
|
442
|
+
else if(isGoogleDriveUri(uri)){
|
|
443
|
+
return getDriveFilePath(uri,context);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
// MediaStore (and general)
|
|
447
|
+
else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
|
448
|
+
|
|
449
|
+
// Return the remote address
|
|
450
|
+
if (isGooglePhotosUri(uri)) {
|
|
451
|
+
String contentPath = getContentFromSegments(uri.getPathSegments());
|
|
452
|
+
if (contentPath != "") {
|
|
453
|
+
return getPath(context, Uri.parse(contentPath));
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if(isGoogleDriveUri(uri)){
|
|
461
|
+
return getDriveFilePath(uri,context);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
return getDataColumn(context, uri, null, null);
|
|
465
|
+
}
|
|
466
|
+
// File
|
|
467
|
+
else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
|
468
|
+
return uri.getPath();
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
private static String getDriveFilePath(Uri uri,Context context){
|
|
475
|
+
Uri returnUri =uri;
|
|
476
|
+
Cursor returnCursor = context.getContentResolver().query(returnUri, null, null, null, null);
|
|
477
|
+
/*
|
|
478
|
+
* Get the column indexes of the data in the Cursor,
|
|
479
|
+
* * move to the first row in the Cursor, get the data,
|
|
480
|
+
* * and display it.
|
|
481
|
+
* */
|
|
482
|
+
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
|
483
|
+
int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
|
|
484
|
+
returnCursor.moveToFirst();
|
|
485
|
+
String name = (returnCursor.getString(nameIndex));
|
|
486
|
+
String size = (Long.toString(returnCursor.getLong(sizeIndex)));
|
|
487
|
+
File file = new File(context.getCacheDir(),name);
|
|
488
|
+
try {
|
|
489
|
+
InputStream inputStream = context.getContentResolver().openInputStream(uri);
|
|
490
|
+
FileOutputStream outputStream = new FileOutputStream(file);
|
|
491
|
+
int read = 0;
|
|
492
|
+
int maxBufferSize = 1 * 1024 * 1024;
|
|
493
|
+
int bytesAvailable = inputStream.available();
|
|
494
|
+
|
|
495
|
+
//int bufferSize = 1024;
|
|
496
|
+
int bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
|
497
|
+
|
|
498
|
+
final byte[] buffers = new byte[bufferSize];
|
|
499
|
+
while ((read = inputStream.read(buffers)) != -1) {
|
|
500
|
+
outputStream.write(buffers, 0, read);
|
|
501
|
+
}
|
|
502
|
+
Log.e("File Size","Size " + file.length());
|
|
503
|
+
inputStream.close();
|
|
504
|
+
outputStream.close();
|
|
505
|
+
Log.e("File Path","Path " + file.getPath());
|
|
506
|
+
Log.e("File Size","Size " + file.length());
|
|
507
|
+
}catch (Exception e){
|
|
508
|
+
Log.e("Exception",e.getMessage());
|
|
509
|
+
}
|
|
510
|
+
return file.getPath();
|
|
511
|
+
}
|
|
512
|
+
}
|
package/www/FilePath.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var exec = require('cordova/exec');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
/**
|
|
6
|
+
* Resolve native path for given content URL/path.
|
|
7
|
+
* @param {String} path Content URL/path.
|
|
8
|
+
* @param successCallback invoked with a native filesystem path string
|
|
9
|
+
* @param errorCallback invoked if error occurs
|
|
10
|
+
*/
|
|
11
|
+
resolveNativePath: function(path, successCallback, errorCallback) {
|
|
12
|
+
exec(successCallback, errorCallback, "FilePath", "resolveNativePath", [path]);
|
|
13
|
+
}
|
|
14
|
+
};
|