mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-01-19 03:42:52 +08:00
CB-10120 android: Fixing use of constants and PermissionHelper
This closes #179
This commit is contained in:
parent
c12206ebc8
commit
0cd962466d
@ -117,10 +117,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
private Uri scanMe; // Uri of image to be added to content store
|
private Uri scanMe; // Uri of image to be added to content store
|
||||||
private Uri croppedUri;
|
private Uri croppedUri;
|
||||||
|
|
||||||
protected void getReadPermission(int requestCode)
|
|
||||||
{
|
|
||||||
cordova.requestPermission(this, requestCode, permissions[requestCode]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the request and returns PluginResult.
|
* Executes the request and returns PluginResult.
|
||||||
@ -237,38 +233,40 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
* @param returnType Set the type of image to return.
|
* @param returnType Set the type of image to return.
|
||||||
*/
|
*/
|
||||||
public void callTakePicture(int returnType, int encodingType) {
|
public void callTakePicture(int returnType, int encodingType) {
|
||||||
boolean takePicturePermission = cordova.hasPermission(permissions[TAKE_PIC_SEC]);
|
boolean saveAlbumPermission = PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||||
|
boolean takePicturePermission = PermissionHelper.hasPermission(this, Manifest.permission.CAMERA);
|
||||||
|
|
||||||
if (!takePicturePermission) {
|
// CB-10120: The CAMERA permission does not need to be requested unless it is declared
|
||||||
takePicturePermission = true; // This permission is not required, unless we find android.permission.CAMERA in the package
|
// in AndroidManifest.xml. This plugin does not declare it, but others may and so we must
|
||||||
try {
|
// check the package info to determine if the permission is present.
|
||||||
PackageManager packageManager = this.cordova.getActivity().getPackageManager();
|
|
||||||
String[] permissionsInPackage = packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), PackageManager.GET_PERMISSIONS).requestedPermissions;
|
if (!takePicturePermission) {
|
||||||
if (permissionsInPackage != null) {
|
takePicturePermission = true;
|
||||||
for (String permission : permissionsInPackage) {
|
try {
|
||||||
if (permission.equals(Manifest.permission.CAMERA)) {
|
PackageManager packageManager = this.cordova.getActivity().getPackageManager();
|
||||||
takePicturePermission = false;
|
String[] permissionsInPackage = packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), PackageManager.GET_PERMISSIONS).requestedPermissions;
|
||||||
break;
|
if (permissionsInPackage != null) {
|
||||||
}
|
for (String permission : permissionsInPackage) {
|
||||||
}
|
if (permission.equals(Manifest.permission.CAMERA)) {
|
||||||
}
|
takePicturePermission = false;
|
||||||
} catch (NameNotFoundException e) { }
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NameNotFoundException e) {
|
||||||
|
// We are requesting the info for our package, so this should
|
||||||
|
// never be caught
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boolean saveAlbumPermission = cordova.hasPermission(permissions[SAVE_TO_ALBUM_SEC]);
|
|
||||||
if (takePicturePermission && saveAlbumPermission) {
|
if (takePicturePermission && saveAlbumPermission) {
|
||||||
takePicture(returnType, encodingType);
|
takePicture(returnType, encodingType);
|
||||||
|
} else if (saveAlbumPermission && !takePicturePermission) {
|
||||||
|
PermissionHelper.requestPermission(this, TAKE_PIC_SEC, Manifest.permission.CAMERA);
|
||||||
|
} else if (!saveAlbumPermission && takePicturePermission) {
|
||||||
|
PermissionHelper.requestPermission(this, TAKE_PIC_SEC, Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||||
} else {
|
} else {
|
||||||
if (saveAlbumPermission && !takePicturePermission) {
|
PermissionHelper.requestPermissions(this, TAKE_PIC_SEC, permissions);
|
||||||
cordova.requestPermission(this, TAKE_PIC_SEC, permissions[TAKE_PIC_SEC]);
|
|
||||||
}
|
|
||||||
else if (!saveAlbumPermission && takePicturePermission) {
|
|
||||||
cordova.requestPermission(this, TAKE_PIC_SEC, permissions[SAVE_TO_ALBUM_SEC]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cordova.requestPermissions(this, TAKE_PIC_SEC, permissions);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user