diff --git a/package-lock.json b/package-lock.json
index 8dd397d..c5a35cf 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -37,7 +37,7 @@
},
"7.0.0": {
"cordova": ">=9.0.0",
- "cordova-android": ">=10.0.0",
+ "cordova-android": ">=12.0.0",
"cordova-ios": ">=5.1.0"
},
"8.0.0": {
diff --git a/package.json b/package.json
index 31a98fc..239e92a 100644
--- a/package.json
+++ b/package.json
@@ -56,7 +56,7 @@
"cordova": ">=9.0.0"
},
"7.0.0": {
- "cordova-android": ">=10.0.0",
+ "cordova-android": ">=12.0.0",
"cordova-ios": ">=5.1.0",
"cordova": ">=9.0.0"
},
diff --git a/plugin.xml b/plugin.xml
index faf6ceb..a5fc2d2 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -31,7 +31,7 @@
-
+
@@ -55,7 +55,9 @@
-
+
+
+
permissions = new ArrayList<>();
+
+ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+ // Android API 33 and higher
+ switch (mediaType) {
+ case PICTURE:
+ permissions.add(Manifest.permission.READ_MEDIA_IMAGES);
+ break;
+ case VIDEO:
+ permissions.add(Manifest.permission.READ_MEDIA_VIDEO);
+ break;
+ default:
+ permissions.add(Manifest.permission.READ_MEDIA_IMAGES);
+ permissions.add(Manifest.permission.READ_MEDIA_VIDEO);
+ break;
+ }
+ } else {
+ // Android API 32 or lower
+ permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
+ permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
+ }
+
+ if (!storageOnly) {
+ // Add camera permission when not storage.
+ permissions.add(Manifest.permission.CAMERA);
+ }
+
+ return permissions.toArray(new String[0]);
+ }
+
private String getTempDirectoryPath() {
File cache = cordova.getActivity().getCacheDir();
// Create the cache directory if it doesn't exist
@@ -243,8 +275,13 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
* @param encodingType Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
*/
public void callTakePicture(int returnType, int encodingType) {
- boolean saveAlbumPermission = PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
- && PermissionHelper.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
+ String[] storagePermissions = getPermissions(true, mediaType);
+ boolean saveAlbumPermission;
+ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ saveAlbumPermission = this.saveToPhotoAlbum ? hasPermissions(storagePermissions) : true;
+ } else {
+ saveAlbumPermission = hasPermissions(storagePermissions);
+ }
boolean takePicturePermission = PermissionHelper.hasPermission(this, Manifest.permission.CAMERA);
// CB-10120: The CAMERA permission does not need to be requested unless it is declared
@@ -275,10 +312,9 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
} else if (saveAlbumPermission) {
PermissionHelper.requestPermission(this, TAKE_PIC_SEC, Manifest.permission.CAMERA);
} else if (takePicturePermission) {
- PermissionHelper.requestPermissions(this, TAKE_PIC_SEC,
- new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE});
+ PermissionHelper.requestPermissions(this, TAKE_PIC_SEC, storagePermissions);
} else {
- PermissionHelper.requestPermissions(this, TAKE_PIC_SEC, permissions);
+ PermissionHelper.requestPermissions(this, TAKE_PIC_SEC, getPermissions(false, mediaType));
}
}
@@ -1232,6 +1268,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
// delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
if ((currentNumOfImages - numPics) == diff) {
cursor.moveToLast();
+ @SuppressLint("Range")
int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
if (diff == 2) {
id--;
@@ -1391,4 +1428,13 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
this.callbackContext = callbackContext;
}
+
+ private boolean hasPermissions(String[] permissions) {
+ for (String permission: permissions) {
+ if (!PermissionHelper.hasPermission(this, permission)) {
+ return false;
+ }
+ }
+ return true;
+ }
}