CB-10319 android: Adding reflective helper methods for permission requests

This commit is contained in:
riknoll
2016-01-04 15:22:35 -08:00
parent e2193631d5
commit 1d32ea46f0
3 changed files with 149 additions and 20 deletions

View File

@@ -114,12 +114,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
private Uri scanMe; // Uri of image to be added to content store
private Uri croppedUri;
protected void getReadPermission(int requestCode)
{
cordova.requestPermission(this, requestCode, Manifest.permission.READ_EXTERNAL_STORAGE);
}
/**
* Executes the request and returns PluginResult.
*
@@ -178,8 +172,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
// preserve the original exif data and filename in the modified file that is
// created
if(this.mediaType == PICTURE && (this.destType == FILE_URI || this.destType == NATIVE_URI)
&& fileWillBeModified() && !cordova.hasPermission(permissions[0])) {
getReadPermission(SAVE_TO_ALBUM_SEC);
&& fileWillBeModified() && !PermissionHelper.hasPermission(this, permissions[0])) {
PermissionHelper.requestPermission(this, SAVE_TO_ALBUM_SEC, Manifest.permission.READ_EXTERNAL_STORAGE);
} else {
this.getImage(this.srcType, destType, encodingType);
}
@@ -238,10 +232,10 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
* @param returnType Set the type of image to return.
*/
public void callTakePicture(int returnType, int encodingType) {
if (cordova.hasPermission(permissions[0])) {
if (PermissionHelper.hasPermission(this, permissions[0])) {
takePicture(returnType, encodingType);
} else {
getReadPermission(TAKE_PIC_SEC);
PermissionHelper.requestPermission(this, TAKE_PIC_SEC, Manifest.permission.READ_EXTERNAL_STORAGE);
}
}