forked from dpa99c/cordova-diagnostic-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Android) Support new media storage permissions on Android 13 / API 33.
Resolves dpa99c#488.
- Loading branch information
Showing
4 changed files
with
84 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3623,7 +3623,13 @@ While the [cordova-diagnostic-plugin-example](https://github.com/dpa99c/cordova- | |
|
||
##### Android Camera permissions | ||
|
||
Note that the Android variant of [`requestCameraAuthorization()`](#requestcameraauthorization) requests the `READ_EXTERNAL_STORAGE` permission, in addition to the `CAMERA` permission. | ||
Note that the Android variant of [`requestCameraAuthorization()`](#requestcameraauthorization), in addition to the `CAMERA` permission, by default also requests storage permissions. | ||
This is because the Android camera API requires access to the device's storage to store captured images and videos. | ||
|
||
On Android <=12, this requires the `WRITE_EXTERNAL_STORAGE` and `READ_EXTERNAL_STORAGE` permissions. | ||
On Android >12, this requires the `READ_MEDIA_IMAGES` and `READ_MEDIA_VIDEO` permissions. | ||
|
||
the `READ_EXTERNAL_STORAGE` permission. | ||
This is because the [[email protected]+](https://github.com/apache/cordova-plugin-camera) requires both of these permissions. | ||
|
||
So to use this method in conjunction with the Cordova camera plugin, make sure you are using the most recent `cordova-plugin-camera` release: v2.2.0 or above. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,14 +30,14 @@ var Diagnostic_Camera = (function(){ | |
|
||
function combineCameraStatuses(statuses){ | ||
var cameraStatus = statuses[Diagnostic.permission.CAMERA], | ||
mediaStatus = statuses[Diagnostic.permission.READ_EXTERNAL_STORAGE], | ||
storageStatus = statuses[Diagnostic.permission.READ_EXTERNAL_STORAGE] || statuses[Diagnostic.permission.READ_MEDIA_IMAGES], | ||
status; | ||
|
||
if(cameraStatus === Diagnostic.permissionStatus.DENIED_ALWAYS || mediaStatus === Diagnostic.permissionStatus.DENIED_ALWAYS){ | ||
if(cameraStatus === Diagnostic.permissionStatus.DENIED_ALWAYS || storageStatus === Diagnostic.permissionStatus.DENIED_ALWAYS){ | ||
status = Diagnostic.permissionStatus.DENIED_ALWAYS; | ||
}else if(cameraStatus === Diagnostic.permissionStatus.DENIED_ONCE || mediaStatus === Diagnostic.permissionStatus.DENIED_ONCE){ | ||
}else if(cameraStatus === Diagnostic.permissionStatus.DENIED_ONCE || storageStatus === Diagnostic.permissionStatus.DENIED_ONCE){ | ||
status = Diagnostic.permissionStatus.DENIED_ONCE; | ||
}else if(cameraStatus === Diagnostic.permissionStatus.NOT_REQUESTED || mediaStatus === Diagnostic.permissionStatus.NOT_REQUESTED){ | ||
}else if(cameraStatus === Diagnostic.permissionStatus.NOT_REQUESTED || storageStatus === Diagnostic.permissionStatus.NOT_REQUESTED){ | ||
status = Diagnostic.permissionStatus.NOT_REQUESTED; | ||
}else{ | ||
status = Diagnostic.permissionStatus.GRANTED; | ||
|
@@ -130,22 +130,22 @@ var Diagnostic_Camera = (function(){ | |
* - {Function} successCallback - function to call on successful request for runtime permissions. | ||
* This callback function is passed a single string parameter which defines the resulting authorisation status as a value in cordova.plugins.diagnostic.permissionStatus. | ||
* - {Function} errorCallback - function to call on failure to request authorisation. | ||
* - {Boolean} externalStorage - (Android only) If true, requests permission for READ_EXTERNAL_STORAGE in addition to CAMERA run-time permission. | ||
* [email protected]+ requires both of these permissions. Defaults to true. | ||
* - {Boolean} externalStorage - (Android only) If true, requests storage permissions for in addition to CAMERA run-time permission. | ||
* Defaults to true. | ||
*/ | ||
Diagnostic_Camera.requestCameraAuthorization = function(params){ | ||
params = mapFromLegacyCameraApi.apply(this, arguments); | ||
|
||
var permissions = [Diagnostic.permission.CAMERA]; | ||
if(params.externalStorage !== false){ | ||
permissions.push(Diagnostic.permission.READ_EXTERNAL_STORAGE); | ||
} | ||
|
||
params.successCallback = params.successCallback || function(){}; | ||
var onSuccess = function(statuses){ | ||
params.successCallback(numberOfKeys(statuses) > 1 ? combineCameraStatuses(statuses): statuses[Diagnostic.permission.CAMERA]); | ||
}; | ||
Diagnostic.requestRuntimePermissions(onSuccess, params.errorCallback, permissions); | ||
|
||
return cordova.exec(onSuccess, | ||
params.errorCallback, | ||
'Diagnostic_Camera', | ||
'requestCameraAuthorization', | ||
[!!params.externalStorage]); | ||
}; | ||
|
||
/** | ||
|
@@ -161,16 +161,16 @@ var Diagnostic_Camera = (function(){ | |
Diagnostic_Camera.getCameraAuthorizationStatus = function(params){ | ||
params = mapFromLegacyCameraApi.apply(this, arguments); | ||
|
||
var permissions = [Diagnostic.permission.CAMERA]; | ||
if(params.externalStorage !== false){ | ||
permissions.push(Diagnostic.permission.READ_EXTERNAL_STORAGE); | ||
} | ||
|
||
params.successCallback = params.successCallback || function(){}; | ||
var onSuccess = function(statuses){ | ||
params.successCallback(numberOfKeys(statuses) > 1 ? combineCameraStatuses(statuses): statuses[Diagnostic.permission.CAMERA]); | ||
}; | ||
Diagnostic.getPermissionsAuthorizationStatus(onSuccess, params.errorCallback, permissions); | ||
|
||
return cordova.exec(onSuccess, | ||
params.errorCallback, | ||
'Diagnostic_Camera', | ||
'getCameraAuthorizationStatus', | ||
[!!params.externalStorage]); | ||
}; | ||
|
||
/** | ||
|