Skip to content

Commit 14d3cfb

Browse files
committed
Proper error if WRITE_EXTERNAL_STORAGE is required but missing the declaration
1 parent a10da73 commit 14d3cfb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/android/CameraLauncher.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ else if ((this.srcType == PHOTOLIBRARY) || (this.srcType == SAVEDPHOTOALBUM)) {
196196
this.getImage(this.srcType, destType);
197197
}
198198
}
199+
catch (IllegalStateException e)
200+
{
201+
callbackContext.error(e.getLocalizedMessage());
202+
PluginResult r = new PluginResult(PluginResult.Status.ERROR);
203+
callbackContext.sendPluginResult(r);
204+
return true;
205+
}
199206
catch (IllegalArgumentException e)
200207
{
201208
callbackContext.error("Illegal Argument Exception");
@@ -238,7 +245,7 @@ private String getTempDirectoryPath() {
238245
* @param returnType Set the type of image to return.
239246
* @param encodingType Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
240247
*/
241-
public void callTakePicture(int returnType, int encodingType) {
248+
public void callTakePicture(int returnType, int encodingType) throws IllegalStateException {
242249

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

284291
if (saveToPhotoAlbum && !writeExternalPermissionGranted) {
292+
// This block only applies for API 24-28
293+
// because writeExternalPermissionGranted is always true on API 29+
294+
if (!manifestContainsWriteExternalPermission) {
295+
throw new IllegalStateException("WRITE_EXTERNAL_STORAGE permission not declared in AndroidManifest");
296+
}
297+
285298
requiredPermissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
286299
}
287300

0 commit comments

Comments
 (0)