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)
@ -177,11 +185,11 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
callbackContext.sendPluginResult(r);
return true;
}
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
r.setKeepCallback(true);
callbackContext.sendPluginResult(r);
return true;
}
return false;
@ -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 {
@ -303,7 +310,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
* @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
* @param srcType The album to get image from.
* @param returnType Set the type of image to return.
* @param encodingType
* @param encodingType
*/
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
// TODO: Images from kitkat filechooser not going into crop function
@ -354,7 +361,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
/**
* Brings up the UI to perform crop on passed image URI
*
*
* @param picUri
*/
private void performCrop(Uri picUri, int destType, Intent cameraIntent) {
@ -437,7 +444,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
// Try to get the bitmap from intent.
bitmap = (Bitmap)intent.getExtras().get("data");
}
// Double-check the bitmap.
if (bitmap == null) {
Log.d(LOG_TAG, "I either have a null image path or bitmap");
@ -463,7 +470,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
}
// If all this is true we shouldn't compress the image.
if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 &&
if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 &&
!this.correctOrientation) {
writeUncompressedImage(uri);
@ -541,7 +548,7 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
// Get filename from uri
String fileName = realPath != null ?
realPath.substring(realPath.lastIndexOf('/') + 1) :
realPath.substring(realPath.lastIndexOf('/') + 1) :
"modified." + (this.encodingType == JPEG ? "jpg" : "png");
String modifiedPath = getTempDirectoryPath() + "/" + fileName;
@ -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.");
@ -687,7 +696,7 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
}
}
}
/**
* Called when the camera view exits.
*
@ -891,7 +900,7 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
*
* @param imagePath
* @return
* @throws IOException
* @throws IOException
*/
private Bitmap getScaledBitmap(String imageUrl) throws IOException {
// If no new width or height were specified return the original bitmap
@ -929,13 +938,13 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
}
}
}
//CB-2292: WTF? Why is the width null?
if(options.outWidth == 0 || options.outHeight == 0)
{
return null;
}
// determine the correct aspect ratio
int[] widthHeight = calculateAspectRatio(options.outWidth, options.outHeight);
@ -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;
}
}