CB-9910 android: Add permission request for some gallery requests

This commit is contained in:
riknoll 2015-11-02 15:07:54 -08:00
parent 5ff225d8df
commit 9b444c39ba

View File

@ -167,7 +167,15 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
this.callTakePicture(destType, encodingType);
}
else if ((this.srcType == PHOTOLIBRARY) || (this.srcType == SAVEDPHOTOALBUM)) {
this.getImage(this.srcType, destType, encodingType);
// Any options that edit the file require READ permissions in order to try and
// 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);
} else {
this.getImage(this.srcType, destType, encodingType);
}
}
}
catch (IllegalArgumentException e)
@ -196,8 +204,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
// SD Card Mounted
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
cache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
"/Android/data/" + cordova.getActivity().getPackageName() + "/cache/");
cache = cordova.getActivity().getExternalCacheDir();
}
// Use internal storage
else {
@ -554,9 +561,10 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
bitmap.compress(compressFormat, this.mQuality, os);
os.close();
// Create an ExifHelper to save the exif data that is lost during compression
ExifHelper exif = new ExifHelper();
if (realPath != null && this.encodingType == JPEG) {
// Create an ExifHelper to save the exif data that is lost during compression
ExifHelper exif = new ExifHelper();
try {
exif.createInFile(realPath);
exif.readExifData();
@ -670,6 +678,7 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
// The modified image is cached by the app in order to get around this and not have to delete you
// application cache I'm adding the current system time to the end of the file url.
this.callbackContext.success("file://" + modifiedPath + "?" + System.currentTimeMillis());
} catch (Exception e) {
e.printStackTrace();
this.failPicture("Error retrieving image.");
@ -1183,7 +1192,13 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
takePicture(this.destType, this.encodingType);
break;
case SAVE_TO_ALBUM_SEC:
this.getImage(this.srcType, this.destType, this.encodingType);
break;
}
}
private boolean fileWillBeModified() {
return (this.targetWidth > 0 && this.targetHeight > 0) ||
this.correctOrientation || this.allowEdit;
}
}