capacitor-camera-module 0.0.19 → 0.0.21

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.
@@ -56,11 +56,8 @@ import android.graphics.Matrix;
56
56
  strings = { Manifest.permission.CAMERA }
57
57
  ),
58
58
  @Permission(
59
- alias = "gallery",
60
- strings = {
61
- Manifest.permission.READ_MEDIA_IMAGES,
62
- Manifest.permission.READ_EXTERNAL_STORAGE
63
- }
59
+ alias = "gallery",
60
+ strings = { Manifest.permission.READ_MEDIA_IMAGES }
64
61
  )
65
62
  }
66
63
  )
@@ -413,8 +410,26 @@ public class CameraModulePlugin extends Plugin {
413
410
 
414
411
  @PluginMethod
415
412
  public void requestGalleryPermission(PluginCall call) {
416
- if (getPermissionState("gallery") != PermissionState.GRANTED) {
417
- requestPermissionForAlias("gallery", call, "galleryPermissionCallback");
413
+ String[] permissionsToRequest;
414
+
415
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
416
+ permissionsToRequest = new String[]{ Manifest.permission.READ_MEDIA_IMAGES };
417
+ } else {
418
+ permissionsToRequest = new String[]{ Manifest.permission.READ_EXTERNAL_STORAGE };
419
+ }
420
+
421
+ // Verificar si ya están concedidos
422
+ boolean granted = true;
423
+ for (String perm : permissionsToRequest) {
424
+ if (ContextCompat.checkSelfPermission(getContext(), perm) != PackageManager.PERMISSION_GRANTED) {
425
+ granted = false;
426
+ break;
427
+ }
428
+ }
429
+
430
+ if (!granted) {
431
+ // Pedir permisos dinámicamente
432
+ requestPermissions(permissionsToRequest, call, "galleryPermissionCallback");
418
433
  } else {
419
434
  JSObject ret = new JSObject();
420
435
  ret.put("granted", true);
@@ -424,10 +439,17 @@ public class CameraModulePlugin extends Plugin {
424
439
  }
425
440
  }
426
441
 
442
+
427
443
  @PermissionCallback
428
444
  private void galleryPermissionCallback(PluginCall call) {
429
445
  JSObject ret = new JSObject();
430
- boolean granted = getPermissionState("gallery") == PermissionState.GRANTED;
446
+
447
+ boolean granted;
448
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
449
+ granted = ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_MEDIA_IMAGES) == PackageManager.PERMISSION_GRANTED;
450
+ } else {
451
+ granted = ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
452
+ }
431
453
 
432
454
  ret.put("granted", granted);
433
455
  ret.put("status", granted ? "granted" : "denied");
@@ -436,6 +458,7 @@ public class CameraModulePlugin extends Plugin {
436
458
  call.resolve(ret);
437
459
  }
438
460
 
461
+
439
462
  @PluginMethod
440
463
  public void checkAndRequestGalleryPermission(PluginCall call) {
441
464
  if (getPermissionState("gallery") == PermissionState.GRANTED) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-camera-module",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "Plugin to request permissiones view camera take phots",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",