Skip to content

Commit

Permalink
Proper error if WRITE_EXTERNAL_STORAGE is required but missing the de…
Browse files Browse the repository at this point in the history
…claration
  • Loading branch information
breautek committed Oct 28, 2024
1 parent a10da73 commit 14d3cfb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/android/CameraLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ else if ((this.srcType == PHOTOLIBRARY) || (this.srcType == SAVEDPHOTOALBUM)) {
this.getImage(this.srcType, destType);
}
}
catch (IllegalStateException e)
{
callbackContext.error(e.getLocalizedMessage());
PluginResult r = new PluginResult(PluginResult.Status.ERROR);
callbackContext.sendPluginResult(r);
return true;
}
catch (IllegalArgumentException e)
{
callbackContext.error("Illegal Argument Exception");
Expand Down Expand Up @@ -238,7 +245,7 @@ private String getTempDirectoryPath() {
* @param returnType Set the type of image to return.
* @param encodingType Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
*/
public void callTakePicture(int returnType, int encodingType) {
public void callTakePicture(int returnType, int encodingType) throws IllegalStateException {

// CB-10120: The CAMERA permission does not need to be requested unless it is declared
// in AndroidManifest.xml. This plugin does not declare it, but others may and so we must
Expand Down Expand Up @@ -282,6 +289,12 @@ else if (permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
}

if (saveToPhotoAlbum && !writeExternalPermissionGranted) {
// This block only applies for API 24-28
// because writeExternalPermissionGranted is always true on API 29+
if (!manifestContainsWriteExternalPermission) {
throw new IllegalStateException("WRITE_EXTERNAL_STORAGE permission not declared in AndroidManifest");
}

requiredPermissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}

Expand Down

0 comments on commit 14d3cfb

Please sign in to comment.