@capacitor/camera 1.0.5 → 1.2.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/CHANGELOG.md +50 -0
- package/README.md +64 -13
- package/android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.java +127 -11
- package/dist/docs.json +212 -3
- package/dist/esm/definitions.d.ts +106 -0
- package/dist/esm/definitions.js +9 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +3 -1
- package/dist/esm/web.js +47 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +56 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +57 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CameraPlugin.m +1 -0
- package/ios/Plugin/CameraPlugin.swift +120 -26
- package/ios/Plugin/CameraTypes.swift +1 -0
- package/ios/Plugin/ImageSaver.swift +20 -0
- package/package.json +4 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,56 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.2.0](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/camera@1.1.2...@capacitor/camera@1.2.0) (2021-11-03)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **camera:** Add new method for multiple image picking from gallery ([#671](https://github.com/ionic-team/capacitor-plugins/issues/671)) ([a49c590](https://github.com/ionic-team/capacitor-plugins/commit/a49c5901683da12438fbafbd1bf6ae91133d18ed))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [1.1.2](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/camera@1.1.1...@capacitor/camera@1.1.2) (2021-10-14)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* remove postpublish scripts ([#656](https://github.com/ionic-team/capacitor-plugins/issues/656)) ([ed6ac49](https://github.com/ionic-team/capacitor-plugins/commit/ed6ac499ebf4a47525071ccbfc36c27503e11f60))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## [1.1.1](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/camera@1.1.0...@capacitor/camera@1.1.1) (2021-10-13)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
32
|
+
|
|
33
|
+
* correct addListeners links ([#655](https://github.com/ionic-team/capacitor-plugins/issues/655)) ([f9871e7](https://github.com/ionic-team/capacitor-plugins/commit/f9871e7bd53478addb21155e148829f550c0e457))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# [1.1.0](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/camera@1.0.5...@capacitor/camera@1.1.0) (2021-09-15)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Bug Fixes
|
|
43
|
+
|
|
44
|
+
* **camera:** saveToGallery for edited images ([#602](https://github.com/ionic-team/capacitor-plugins/issues/602)) ([b5ac27d](https://github.com/ionic-team/capacitor-plugins/commit/b5ac27d59181ec3acc2909b2569d8ab45a829b1c))
|
|
45
|
+
* **camera:** set settings again on callbacks ([#595](https://github.com/ionic-team/capacitor-plugins/issues/595)) ([908bd68](https://github.com/ionic-team/capacitor-plugins/commit/908bd688767e374cf8e96b3def08bd33dcdfd2aa))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Features
|
|
49
|
+
|
|
50
|
+
* **camera:** Return if image was saved to gallery ([#599](https://github.com/ionic-team/capacitor-plugins/issues/599)) ([594af3b](https://github.com/ionic-team/capacitor-plugins/commit/594af3be0982371e6c61e4bdb830c6bbb3963913))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
6
56
|
## [1.0.5](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/camera@1.0.4...@capacitor/camera@1.0.5) (2021-09-01)
|
|
7
57
|
|
|
8
58
|
|
package/README.md
CHANGED
|
@@ -73,6 +73,7 @@ const takePicture = async () => {
|
|
|
73
73
|
<docgen-index>
|
|
74
74
|
|
|
75
75
|
* [`getPhoto(...)`](#getphoto)
|
|
76
|
+
* [`pickImages(...)`](#pickimages)
|
|
76
77
|
* [`checkPermissions()`](#checkpermissions)
|
|
77
78
|
* [`requestPermissions(...)`](#requestpermissions)
|
|
78
79
|
* [Interfaces](#interfaces)
|
|
@@ -104,6 +105,26 @@ with the camera.
|
|
|
104
105
|
--------------------
|
|
105
106
|
|
|
106
107
|
|
|
108
|
+
### pickImages(...)
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
pickImages(options: GalleryImageOptions) => Promise<GalleryPhotos>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Allows the user to pick multiple pictures from the photo gallery.
|
|
115
|
+
On iOS 13 and older it only allows to pick one picture.
|
|
116
|
+
|
|
117
|
+
| Param | Type |
|
|
118
|
+
| ------------- | ------------------------------------------------------------------- |
|
|
119
|
+
| **`options`** | <code><a href="#galleryimageoptions">GalleryImageOptions</a></code> |
|
|
120
|
+
|
|
121
|
+
**Returns:** <code>Promise<<a href="#galleryphotos">GalleryPhotos</a>></code>
|
|
122
|
+
|
|
123
|
+
**Since:** 1.2.0
|
|
124
|
+
|
|
125
|
+
--------------------
|
|
126
|
+
|
|
127
|
+
|
|
107
128
|
### checkPermissions()
|
|
108
129
|
|
|
109
130
|
```typescript
|
|
@@ -143,14 +164,15 @@ Request camera and photo album permissions
|
|
|
143
164
|
|
|
144
165
|
#### Photo
|
|
145
166
|
|
|
146
|
-
| Prop | Type
|
|
147
|
-
| ------------------ |
|
|
148
|
-
| **`base64String`** | <code>string</code>
|
|
149
|
-
| **`dataUrl`** | <code>string</code>
|
|
150
|
-
| **`path`** | <code>string</code>
|
|
151
|
-
| **`webPath`** | <code>string</code>
|
|
152
|
-
| **`exif`** | <code>any</code>
|
|
153
|
-
| **`format`** | <code>string</code>
|
|
167
|
+
| Prop | Type | Description | Since |
|
|
168
|
+
| ------------------ | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
169
|
+
| **`base64String`** | <code>string</code> | The base64 encoded string representation of the image, if using <a href="#cameraresulttype">CameraResultType.Base64</a>. | 1.0.0 |
|
|
170
|
+
| **`dataUrl`** | <code>string</code> | The url starting with 'data:image/jpeg;base64,' and the base64 encoded string representation of the image, if using <a href="#cameraresulttype">CameraResultType.DataUrl</a>. | 1.0.0 |
|
|
171
|
+
| **`path`** | <code>string</code> | If using <a href="#cameraresulttype">CameraResultType.Uri</a>, the path will contain a full, platform-specific file URL that can be read later using the Filsystem API. | 1.0.0 |
|
|
172
|
+
| **`webPath`** | <code>string</code> | webPath returns a path that can be used to set the src attribute of an image for efficient loading and rendering. | 1.0.0 |
|
|
173
|
+
| **`exif`** | <code>any</code> | Exif data, if any, retrieved from the image | 1.0.0 |
|
|
174
|
+
| **`format`** | <code>string</code> | The format of the image, ex: jpeg, png, gif. iOS and Android only support jpeg. Web supports jpeg and png. gif is only supported if using file input. | 1.0.0 |
|
|
175
|
+
| **`saved`** | <code>boolean</code> | Whether if the image was saved to the gallery or not. On Android and iOS, saving to the gallery can fail if the user didn't grant the required permissions. On Web there is no gallery, so always returns false. | 1.1.0 |
|
|
154
176
|
|
|
155
177
|
|
|
156
178
|
#### ImageOptions
|
|
@@ -175,6 +197,35 @@ Request camera and photo album permissions
|
|
|
175
197
|
| **`promptLabelPicture`** | <code>string</code> | Text value to use when displaying the prompt. The label of the button to open the camera. | <code>: 'Take Picture'</code> | 1.0.0 |
|
|
176
198
|
|
|
177
199
|
|
|
200
|
+
#### GalleryPhotos
|
|
201
|
+
|
|
202
|
+
| Prop | Type | Description | Since |
|
|
203
|
+
| ------------ | --------------------------- | ------------------------------- | ----- |
|
|
204
|
+
| **`photos`** | <code>GalleryPhoto[]</code> | Array of all the picked photos. | 1.2.0 |
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
#### GalleryPhoto
|
|
208
|
+
|
|
209
|
+
| Prop | Type | Description | Since |
|
|
210
|
+
| ------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------- | ----- |
|
|
211
|
+
| **`path`** | <code>string</code> | Full, platform-specific file URL that can be read later using the Filsystem API. | 1.2.0 |
|
|
212
|
+
| **`webPath`** | <code>string</code> | webPath returns a path that can be used to set the src attribute of an image for efficient loading and rendering. | 1.2.0 |
|
|
213
|
+
| **`exif`** | <code>any</code> | Exif data, if any, retrieved from the image | 1.2.0 |
|
|
214
|
+
| **`format`** | <code>string</code> | The format of the image, ex: jpeg, png, gif. iOS and Android only support jpeg. Web supports jpeg, png and gif. | 1.2.0 |
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
#### GalleryImageOptions
|
|
218
|
+
|
|
219
|
+
| Prop | Type | Description | Default | Since |
|
|
220
|
+
| ------------------------ | -------------------------------------- | ------------------------------------------------------------------------------------------ | --------------------------- | ----- |
|
|
221
|
+
| **`quality`** | <code>number</code> | The quality of image to return as JPEG, from 0-100 | | 1.2.0 |
|
|
222
|
+
| **`width`** | <code>number</code> | The width of the saved image | | 1.2.0 |
|
|
223
|
+
| **`height`** | <code>number</code> | The height of the saved image | | 1.2.0 |
|
|
224
|
+
| **`correctOrientation`** | <code>boolean</code> | Whether to automatically rotate the image "up" to correct for orientation in portrait mode | <code>: true</code> | 1.2.0 |
|
|
225
|
+
| **`presentationStyle`** | <code>'fullscreen' \| 'popover'</code> | iOS only: The presentation style of the Camera. | <code>: 'fullscreen'</code> | 1.2.0 |
|
|
226
|
+
| **`limit`** | <code>number</code> | iOS only: Maximum number of pictures the user will be able to choose. | <code>0 (unlimited)</code> | 1.2.0 |
|
|
227
|
+
|
|
228
|
+
|
|
178
229
|
#### PermissionStatus
|
|
179
230
|
|
|
180
231
|
| Prop | Type |
|
|
@@ -222,11 +273,11 @@ Request camera and photo album permissions
|
|
|
222
273
|
|
|
223
274
|
#### CameraSource
|
|
224
275
|
|
|
225
|
-
| Members | Value |
|
|
226
|
-
| ------------ | --------------------- |
|
|
227
|
-
| **`Prompt`** | <code>'PROMPT'</code> |
|
|
228
|
-
| **`Camera`** | <code>'CAMERA'</code> |
|
|
229
|
-
| **`Photos`** | <code>'PHOTOS'</code> |
|
|
276
|
+
| Members | Value | Description |
|
|
277
|
+
| ------------ | --------------------- | ------------------------------------------------------------------ |
|
|
278
|
+
| **`Prompt`** | <code>'PROMPT'</code> | Prompts the user to select either the photo album or take a photo. |
|
|
279
|
+
| **`Camera`** | <code>'CAMERA'</code> | Take a new photo using the camera. |
|
|
280
|
+
| **`Photos`** | <code>'PHOTOS'</code> | Pick an existing photo fron the gallery or photo album. |
|
|
230
281
|
|
|
231
282
|
|
|
232
283
|
#### CameraDirection
|
|
@@ -2,6 +2,7 @@ package com.capacitorjs.plugins.camera;
|
|
|
2
2
|
|
|
3
3
|
import android.Manifest;
|
|
4
4
|
import android.app.Activity;
|
|
5
|
+
import android.content.ActivityNotFoundException;
|
|
5
6
|
import android.content.Intent;
|
|
6
7
|
import android.content.pm.PackageManager;
|
|
7
8
|
import android.content.pm.ResolveInfo;
|
|
@@ -35,6 +36,8 @@ import java.io.InputStream;
|
|
|
35
36
|
import java.util.ArrayList;
|
|
36
37
|
import java.util.List;
|
|
37
38
|
import java.util.Map;
|
|
39
|
+
import java.util.concurrent.Executor;
|
|
40
|
+
import java.util.concurrent.Executors;
|
|
38
41
|
import org.json.JSONException;
|
|
39
42
|
|
|
40
43
|
/**
|
|
@@ -67,6 +70,7 @@ public class CameraPlugin extends Plugin {
|
|
|
67
70
|
private static final String PERMISSION_DENIED_ERROR_PHOTOS = "User denied access to photos";
|
|
68
71
|
private static final String NO_CAMERA_ERROR = "Device doesn't have a camera available";
|
|
69
72
|
private static final String NO_CAMERA_ACTIVITY_ERROR = "Unable to resolve camera activity";
|
|
73
|
+
private static final String NO_PHOTO_ACTIVITY_ERROR = "Unable to resolve photo activity";
|
|
70
74
|
private static final String IMAGE_FILE_SAVE_ERROR = "Unable to create photo on disk";
|
|
71
75
|
private static final String IMAGE_PROCESS_NO_FILE_ERROR = "Unable to process image, file not found on disk";
|
|
72
76
|
private static final String UNABLE_TO_PROCESS_IMAGE = "Unable to process image";
|
|
@@ -78,6 +82,8 @@ public class CameraPlugin extends Plugin {
|
|
|
78
82
|
private Uri imageFileUri;
|
|
79
83
|
private Uri imagePickedContentUri;
|
|
80
84
|
private boolean isEdited = false;
|
|
85
|
+
private boolean isFirstRequest = true;
|
|
86
|
+
private boolean isSaved = false;
|
|
81
87
|
|
|
82
88
|
private CameraSettings settings = new CameraSettings();
|
|
83
89
|
|
|
@@ -88,6 +94,12 @@ public class CameraPlugin extends Plugin {
|
|
|
88
94
|
doShow(call);
|
|
89
95
|
}
|
|
90
96
|
|
|
97
|
+
@PluginMethod
|
|
98
|
+
public void pickImages(PluginCall call) {
|
|
99
|
+
settings = getSettings(call);
|
|
100
|
+
openPhotos(call, true);
|
|
101
|
+
}
|
|
102
|
+
|
|
91
103
|
private void doShow(PluginCall call) {
|
|
92
104
|
switch (settings.getSource()) {
|
|
93
105
|
case CAMERA:
|
|
@@ -145,7 +157,8 @@ public class CameraPlugin extends Plugin {
|
|
|
145
157
|
boolean hasPhotoPerms = getPermissionState(PHOTOS) == PermissionState.GRANTED;
|
|
146
158
|
|
|
147
159
|
// If we want to save to the gallery, we need two permissions
|
|
148
|
-
if (settings.isSaveToGallery() && !(hasCameraPerms && hasPhotoPerms)) {
|
|
160
|
+
if (settings.isSaveToGallery() && !(hasCameraPerms && hasPhotoPerms) && isFirstRequest) {
|
|
161
|
+
isFirstRequest = false;
|
|
149
162
|
String[] aliases;
|
|
150
163
|
if (needCameraPerms) {
|
|
151
164
|
aliases = new String[] { CAMERA, PHOTOS };
|
|
@@ -247,15 +260,29 @@ public class CameraPlugin extends Plugin {
|
|
|
247
260
|
}
|
|
248
261
|
|
|
249
262
|
public void openPhotos(final PluginCall call) {
|
|
250
|
-
|
|
263
|
+
openPhotos(call, false);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
private void openPhotos(final PluginCall call, boolean multiple) {
|
|
267
|
+
if (multiple || checkPhotosPermissions(call)) {
|
|
251
268
|
Intent intent = new Intent(Intent.ACTION_PICK);
|
|
269
|
+
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiple);
|
|
252
270
|
intent.setType("image/*");
|
|
253
|
-
|
|
271
|
+
try {
|
|
272
|
+
if (multiple) {
|
|
273
|
+
startActivityForResult(call, intent, "processPickedImages");
|
|
274
|
+
} else {
|
|
275
|
+
startActivityForResult(call, intent, "processPickedImage");
|
|
276
|
+
}
|
|
277
|
+
} catch (ActivityNotFoundException ex) {
|
|
278
|
+
call.reject(NO_PHOTO_ACTIVITY_ERROR);
|
|
279
|
+
}
|
|
254
280
|
}
|
|
255
281
|
}
|
|
256
282
|
|
|
257
283
|
@ActivityCallback
|
|
258
284
|
public void processCameraImage(PluginCall call, ActivityResult result) {
|
|
285
|
+
settings = getSettings(call);
|
|
259
286
|
if (imageFileSavePath == null) {
|
|
260
287
|
call.reject(IMAGE_PROCESS_NO_FILE_ERROR);
|
|
261
288
|
return;
|
|
@@ -276,6 +303,7 @@ public class CameraPlugin extends Plugin {
|
|
|
276
303
|
|
|
277
304
|
@ActivityCallback
|
|
278
305
|
public void processPickedImage(PluginCall call, ActivityResult result) {
|
|
306
|
+
settings = getSettings(call);
|
|
279
307
|
Intent data = result.getData();
|
|
280
308
|
if (data == null) {
|
|
281
309
|
call.reject("No image picked");
|
|
@@ -289,6 +317,35 @@ public class CameraPlugin extends Plugin {
|
|
|
289
317
|
processPickedImage(u, call);
|
|
290
318
|
}
|
|
291
319
|
|
|
320
|
+
@ActivityCallback
|
|
321
|
+
public void processPickedImages(PluginCall call, ActivityResult result) {
|
|
322
|
+
Intent data = result.getData();
|
|
323
|
+
if (data != null && data.getClipData() != null) {
|
|
324
|
+
Executor executor = Executors.newSingleThreadExecutor();
|
|
325
|
+
executor.execute(
|
|
326
|
+
() -> {
|
|
327
|
+
JSObject ret = new JSObject();
|
|
328
|
+
JSArray photos = new JSArray();
|
|
329
|
+
int count = data.getClipData().getItemCount();
|
|
330
|
+
for (int i = 0; i < count; i++) {
|
|
331
|
+
Uri imageUri = data.getClipData().getItemAt(i).getUri();
|
|
332
|
+
JSObject processResult = processPickedImages(imageUri);
|
|
333
|
+
if (processResult.getString("error") != null && !processResult.getString("error").isEmpty()) {
|
|
334
|
+
call.reject(processResult.getString("error"));
|
|
335
|
+
return;
|
|
336
|
+
} else {
|
|
337
|
+
photos.put(processPickedImages(imageUri));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
ret.put("photos", photos);
|
|
341
|
+
call.resolve(ret);
|
|
342
|
+
}
|
|
343
|
+
);
|
|
344
|
+
} else {
|
|
345
|
+
call.reject("No images picked");
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
292
349
|
private void processPickedImage(Uri imageUri, PluginCall call) {
|
|
293
350
|
InputStream imageStream = null;
|
|
294
351
|
|
|
@@ -317,10 +374,61 @@ public class CameraPlugin extends Plugin {
|
|
|
317
374
|
}
|
|
318
375
|
}
|
|
319
376
|
|
|
377
|
+
private JSObject processPickedImages(Uri imageUri) {
|
|
378
|
+
InputStream imageStream = null;
|
|
379
|
+
JSObject ret = new JSObject();
|
|
380
|
+
try {
|
|
381
|
+
imageStream = getContext().getContentResolver().openInputStream(imageUri);
|
|
382
|
+
Bitmap bitmap = BitmapFactory.decodeStream(imageStream);
|
|
383
|
+
|
|
384
|
+
if (bitmap == null) {
|
|
385
|
+
ret.put("error", "Unable to process bitmap");
|
|
386
|
+
return ret;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
ExifWrapper exif = ImageUtils.getExifData(getContext(), bitmap, imageUri);
|
|
390
|
+
try {
|
|
391
|
+
bitmap = prepareBitmap(bitmap, imageUri, exif);
|
|
392
|
+
} catch (IOException e) {
|
|
393
|
+
ret.put("error", UNABLE_TO_PROCESS_IMAGE);
|
|
394
|
+
return ret;
|
|
395
|
+
}
|
|
396
|
+
// Compress the final image and prepare for output to client
|
|
397
|
+
ByteArrayOutputStream bitmapOutputStream = new ByteArrayOutputStream();
|
|
398
|
+
bitmap.compress(Bitmap.CompressFormat.JPEG, settings.getQuality(), bitmapOutputStream);
|
|
399
|
+
|
|
400
|
+
Uri newUri = getTempImage(imageUri, bitmapOutputStream);
|
|
401
|
+
exif.copyExif(newUri.getPath());
|
|
402
|
+
if (newUri != null) {
|
|
403
|
+
ret.put("format", "jpeg");
|
|
404
|
+
ret.put("exif", exif.toJson());
|
|
405
|
+
ret.put("path", newUri.toString());
|
|
406
|
+
ret.put("webPath", FileUtils.getPortablePath(getContext(), bridge.getLocalUrl(), newUri));
|
|
407
|
+
} else {
|
|
408
|
+
ret.put("error", UNABLE_TO_PROCESS_IMAGE);
|
|
409
|
+
}
|
|
410
|
+
return ret;
|
|
411
|
+
} catch (OutOfMemoryError err) {
|
|
412
|
+
ret.put("error", "Out of memory");
|
|
413
|
+
} catch (FileNotFoundException ex) {
|
|
414
|
+
ret.put("error", "No such image found");
|
|
415
|
+
Logger.error(getLogTag(), "No such image found", ex);
|
|
416
|
+
} finally {
|
|
417
|
+
if (imageStream != null) {
|
|
418
|
+
try {
|
|
419
|
+
imageStream.close();
|
|
420
|
+
} catch (IOException e) {
|
|
421
|
+
Logger.error(getLogTag(), UNABLE_TO_PROCESS_IMAGE, e);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return ret;
|
|
426
|
+
}
|
|
427
|
+
|
|
320
428
|
@ActivityCallback
|
|
321
429
|
private void processEditedImage(PluginCall call, ActivityResult result) {
|
|
322
430
|
isEdited = true;
|
|
323
|
-
|
|
431
|
+
settings = getSettings(call);
|
|
324
432
|
if (result.getResultCode() == Activity.RESULT_CANCELED) {
|
|
325
433
|
// User cancelled the edit operation, if this file was picked from photos,
|
|
326
434
|
// process the original picked image, otherwise process it as a camera photo
|
|
@@ -389,11 +497,21 @@ public class CameraPlugin extends Plugin {
|
|
|
389
497
|
|
|
390
498
|
boolean saveToGallery = call.getBoolean("saveToGallery", CameraSettings.DEFAULT_SAVE_IMAGE_TO_GALLERY);
|
|
391
499
|
if (saveToGallery && (imageEditedFileSavePath != null || imageFileSavePath != null)) {
|
|
500
|
+
isSaved = true;
|
|
392
501
|
try {
|
|
393
502
|
String fileToSavePath = imageEditedFileSavePath != null ? imageEditedFileSavePath : imageFileSavePath;
|
|
394
503
|
File fileToSave = new File(fileToSavePath);
|
|
395
|
-
MediaStore.Images.Media.insertImage(
|
|
504
|
+
String inserted = MediaStore.Images.Media.insertImage(
|
|
505
|
+
getContext().getContentResolver(),
|
|
506
|
+
fileToSavePath,
|
|
507
|
+
fileToSave.getName(),
|
|
508
|
+
""
|
|
509
|
+
);
|
|
510
|
+
if (inserted == null) {
|
|
511
|
+
isSaved = false;
|
|
512
|
+
}
|
|
396
513
|
} catch (FileNotFoundException e) {
|
|
514
|
+
isSaved = false;
|
|
397
515
|
Logger.error(getLogTag(), IMAGE_GALLERY_SAVE_ERROR, e);
|
|
398
516
|
}
|
|
399
517
|
}
|
|
@@ -435,6 +553,7 @@ public class CameraPlugin extends Plugin {
|
|
|
435
553
|
ret.put("exif", exif.toJson());
|
|
436
554
|
ret.put("path", newUri.toString());
|
|
437
555
|
ret.put("webPath", FileUtils.getPortablePath(getContext(), bridge.getLocalUrl(), newUri));
|
|
556
|
+
ret.put("saved", isSaved);
|
|
438
557
|
call.resolve(ret);
|
|
439
558
|
} else {
|
|
440
559
|
call.reject(UNABLE_TO_PROCESS_IMAGE);
|
|
@@ -567,14 +686,11 @@ public class CameraPlugin extends Plugin {
|
|
|
567
686
|
|
|
568
687
|
private Intent createEditIntent(Uri origPhotoUri) {
|
|
569
688
|
try {
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
getContext().getPackageName() + ".fileprovider",
|
|
573
|
-
new File(origPhotoUri.getPath())
|
|
574
|
-
);
|
|
689
|
+
File editFile = new File(origPhotoUri.getPath());
|
|
690
|
+
Uri editUri = FileProvider.getUriForFile(getActivity(), getContext().getPackageName() + ".fileprovider", editFile);
|
|
575
691
|
Intent editIntent = new Intent(Intent.ACTION_EDIT);
|
|
576
692
|
editIntent.setDataAndType(editUri, "image/*");
|
|
577
|
-
imageEditedFileSavePath =
|
|
693
|
+
imageEditedFileSavePath = editFile.getAbsolutePath();
|
|
578
694
|
int flags = Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
|
|
579
695
|
editIntent.addFlags(flags);
|
|
580
696
|
editIntent.putExtra(MediaStore.EXTRA_OUTPUT, editUri);
|
package/dist/docs.json
CHANGED
|
@@ -29,6 +29,30 @@
|
|
|
29
29
|
],
|
|
30
30
|
"slug": "getphoto"
|
|
31
31
|
},
|
|
32
|
+
{
|
|
33
|
+
"name": "pickImages",
|
|
34
|
+
"signature": "(options: GalleryImageOptions) => Promise<GalleryPhotos>",
|
|
35
|
+
"parameters": [
|
|
36
|
+
{
|
|
37
|
+
"name": "options",
|
|
38
|
+
"docs": "",
|
|
39
|
+
"type": "GalleryImageOptions"
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"returns": "Promise<GalleryPhotos>",
|
|
43
|
+
"tags": [
|
|
44
|
+
{
|
|
45
|
+
"name": "since",
|
|
46
|
+
"text": "1.2.0"
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"docs": "Allows the user to pick multiple pictures from the photo gallery.\nOn iOS 13 and older it only allows to pick one picture.",
|
|
50
|
+
"complexTypes": [
|
|
51
|
+
"GalleryPhotos",
|
|
52
|
+
"GalleryImageOptions"
|
|
53
|
+
],
|
|
54
|
+
"slug": "pickimages"
|
|
55
|
+
},
|
|
32
56
|
{
|
|
33
57
|
"name": "checkPermissions",
|
|
34
58
|
"signature": "() => Promise<PermissionStatus>",
|
|
@@ -152,6 +176,18 @@
|
|
|
152
176
|
"docs": "The format of the image, ex: jpeg, png, gif.\n\niOS and Android only support jpeg.\nWeb supports jpeg and png. gif is only supported if using file input.",
|
|
153
177
|
"complexTypes": [],
|
|
154
178
|
"type": "string"
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"name": "saved",
|
|
182
|
+
"tags": [
|
|
183
|
+
{
|
|
184
|
+
"text": "1.1.0",
|
|
185
|
+
"name": "since"
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
"docs": "Whether if the image was saved to the gallery or not.\n\nOn Android and iOS, saving to the gallery can fail if the user didn't\ngrant the required permissions.\nOn Web there is no gallery, so always returns false.",
|
|
189
|
+
"complexTypes": [],
|
|
190
|
+
"type": "boolean"
|
|
155
191
|
}
|
|
156
192
|
]
|
|
157
193
|
},
|
|
@@ -402,6 +438,179 @@
|
|
|
402
438
|
}
|
|
403
439
|
]
|
|
404
440
|
},
|
|
441
|
+
{
|
|
442
|
+
"name": "GalleryPhotos",
|
|
443
|
+
"slug": "galleryphotos",
|
|
444
|
+
"docs": "",
|
|
445
|
+
"tags": [],
|
|
446
|
+
"methods": [],
|
|
447
|
+
"properties": [
|
|
448
|
+
{
|
|
449
|
+
"name": "photos",
|
|
450
|
+
"tags": [
|
|
451
|
+
{
|
|
452
|
+
"text": "1.2.0",
|
|
453
|
+
"name": "since"
|
|
454
|
+
}
|
|
455
|
+
],
|
|
456
|
+
"docs": "Array of all the picked photos.",
|
|
457
|
+
"complexTypes": [
|
|
458
|
+
"GalleryPhoto"
|
|
459
|
+
],
|
|
460
|
+
"type": "GalleryPhoto[]"
|
|
461
|
+
}
|
|
462
|
+
]
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
"name": "GalleryPhoto",
|
|
466
|
+
"slug": "galleryphoto",
|
|
467
|
+
"docs": "",
|
|
468
|
+
"tags": [],
|
|
469
|
+
"methods": [],
|
|
470
|
+
"properties": [
|
|
471
|
+
{
|
|
472
|
+
"name": "path",
|
|
473
|
+
"tags": [
|
|
474
|
+
{
|
|
475
|
+
"text": "1.2.0",
|
|
476
|
+
"name": "since"
|
|
477
|
+
}
|
|
478
|
+
],
|
|
479
|
+
"docs": "Full, platform-specific file URL that can be read later using the Filsystem API.",
|
|
480
|
+
"complexTypes": [],
|
|
481
|
+
"type": "string | undefined"
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
"name": "webPath",
|
|
485
|
+
"tags": [
|
|
486
|
+
{
|
|
487
|
+
"text": "1.2.0",
|
|
488
|
+
"name": "since"
|
|
489
|
+
}
|
|
490
|
+
],
|
|
491
|
+
"docs": "webPath returns a path that can be used to set the src attribute of an image for efficient\nloading and rendering.",
|
|
492
|
+
"complexTypes": [],
|
|
493
|
+
"type": "string"
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
"name": "exif",
|
|
497
|
+
"tags": [
|
|
498
|
+
{
|
|
499
|
+
"text": "1.2.0",
|
|
500
|
+
"name": "since"
|
|
501
|
+
}
|
|
502
|
+
],
|
|
503
|
+
"docs": "Exif data, if any, retrieved from the image",
|
|
504
|
+
"complexTypes": [],
|
|
505
|
+
"type": "any"
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
"name": "format",
|
|
509
|
+
"tags": [
|
|
510
|
+
{
|
|
511
|
+
"text": "1.2.0",
|
|
512
|
+
"name": "since"
|
|
513
|
+
}
|
|
514
|
+
],
|
|
515
|
+
"docs": "The format of the image, ex: jpeg, png, gif.\n\niOS and Android only support jpeg.\nWeb supports jpeg, png and gif.",
|
|
516
|
+
"complexTypes": [],
|
|
517
|
+
"type": "string"
|
|
518
|
+
}
|
|
519
|
+
]
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
"name": "GalleryImageOptions",
|
|
523
|
+
"slug": "galleryimageoptions",
|
|
524
|
+
"docs": "",
|
|
525
|
+
"tags": [],
|
|
526
|
+
"methods": [],
|
|
527
|
+
"properties": [
|
|
528
|
+
{
|
|
529
|
+
"name": "quality",
|
|
530
|
+
"tags": [
|
|
531
|
+
{
|
|
532
|
+
"text": "1.2.0",
|
|
533
|
+
"name": "since"
|
|
534
|
+
}
|
|
535
|
+
],
|
|
536
|
+
"docs": "The quality of image to return as JPEG, from 0-100",
|
|
537
|
+
"complexTypes": [],
|
|
538
|
+
"type": "number | undefined"
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
"name": "width",
|
|
542
|
+
"tags": [
|
|
543
|
+
{
|
|
544
|
+
"text": "1.2.0",
|
|
545
|
+
"name": "since"
|
|
546
|
+
}
|
|
547
|
+
],
|
|
548
|
+
"docs": "The width of the saved image",
|
|
549
|
+
"complexTypes": [],
|
|
550
|
+
"type": "number | undefined"
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
"name": "height",
|
|
554
|
+
"tags": [
|
|
555
|
+
{
|
|
556
|
+
"text": "1.2.0",
|
|
557
|
+
"name": "since"
|
|
558
|
+
}
|
|
559
|
+
],
|
|
560
|
+
"docs": "The height of the saved image",
|
|
561
|
+
"complexTypes": [],
|
|
562
|
+
"type": "number | undefined"
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
"name": "correctOrientation",
|
|
566
|
+
"tags": [
|
|
567
|
+
{
|
|
568
|
+
"text": ": true",
|
|
569
|
+
"name": "default"
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
"text": "1.2.0",
|
|
573
|
+
"name": "since"
|
|
574
|
+
}
|
|
575
|
+
],
|
|
576
|
+
"docs": "Whether to automatically rotate the image \"up\" to correct for orientation\nin portrait mode",
|
|
577
|
+
"complexTypes": [],
|
|
578
|
+
"type": "boolean | undefined"
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
"name": "presentationStyle",
|
|
582
|
+
"tags": [
|
|
583
|
+
{
|
|
584
|
+
"text": ": 'fullscreen'",
|
|
585
|
+
"name": "default"
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
"text": "1.2.0",
|
|
589
|
+
"name": "since"
|
|
590
|
+
}
|
|
591
|
+
],
|
|
592
|
+
"docs": "iOS only: The presentation style of the Camera.",
|
|
593
|
+
"complexTypes": [],
|
|
594
|
+
"type": "'fullscreen' | 'popover' | undefined"
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
"name": "limit",
|
|
598
|
+
"tags": [
|
|
599
|
+
{
|
|
600
|
+
"text": "0 (unlimited)",
|
|
601
|
+
"name": "default"
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
"text": "1.2.0",
|
|
605
|
+
"name": "since"
|
|
606
|
+
}
|
|
607
|
+
],
|
|
608
|
+
"docs": "iOS only: Maximum number of pictures the user will be able to choose.",
|
|
609
|
+
"complexTypes": [],
|
|
610
|
+
"type": "number | undefined"
|
|
611
|
+
}
|
|
612
|
+
]
|
|
613
|
+
},
|
|
405
614
|
{
|
|
406
615
|
"name": "PermissionStatus",
|
|
407
616
|
"slug": "permissionstatus",
|
|
@@ -481,19 +690,19 @@
|
|
|
481
690
|
"name": "Prompt",
|
|
482
691
|
"value": "'PROMPT'",
|
|
483
692
|
"tags": [],
|
|
484
|
-
"docs": ""
|
|
693
|
+
"docs": "Prompts the user to select either the photo album or take a photo."
|
|
485
694
|
},
|
|
486
695
|
{
|
|
487
696
|
"name": "Camera",
|
|
488
697
|
"value": "'CAMERA'",
|
|
489
698
|
"tags": [],
|
|
490
|
-
"docs": ""
|
|
699
|
+
"docs": "Take a new photo using the camera."
|
|
491
700
|
},
|
|
492
701
|
{
|
|
493
702
|
"name": "Photos",
|
|
494
703
|
"value": "'PHOTOS'",
|
|
495
704
|
"tags": [],
|
|
496
|
-
"docs": ""
|
|
705
|
+
"docs": "Pick an existing photo fron the gallery or photo album."
|
|
497
706
|
}
|
|
498
707
|
]
|
|
499
708
|
},
|