mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-01-19 03:42:52 +08:00
CB-9910 android: Add permission request for some gallery requests
This commit is contained in:
parent
5ff225d8df
commit
9b444c39ba
@ -167,9 +167,17 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
this.callTakePicture(destType, encodingType);
|
this.callTakePicture(destType, encodingType);
|
||||||
}
|
}
|
||||||
else if ((this.srcType == PHOTOLIBRARY) || (this.srcType == SAVEDPHOTOALBUM)) {
|
else if ((this.srcType == PHOTOLIBRARY) || (this.srcType == SAVEDPHOTOALBUM)) {
|
||||||
|
// 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);
|
this.getImage(this.srcType, destType, encodingType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (IllegalArgumentException e)
|
catch (IllegalArgumentException e)
|
||||||
{
|
{
|
||||||
callbackContext.error("Illegal Argument Exception");
|
callbackContext.error("Illegal Argument Exception");
|
||||||
@ -196,8 +204,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
|
|
||||||
// SD Card Mounted
|
// SD Card Mounted
|
||||||
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||||
cache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
|
cache = cordova.getActivity().getExternalCacheDir();
|
||||||
"/Android/data/" + cordova.getActivity().getPackageName() + "/cache/");
|
|
||||||
}
|
}
|
||||||
// Use internal storage
|
// Use internal storage
|
||||||
else {
|
else {
|
||||||
@ -554,9 +561,10 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
|
|||||||
bitmap.compress(compressFormat, this.mQuality, os);
|
bitmap.compress(compressFormat, this.mQuality, os);
|
||||||
os.close();
|
os.close();
|
||||||
|
|
||||||
|
if (realPath != null && this.encodingType == JPEG) {
|
||||||
// Create an ExifHelper to save the exif data that is lost during compression
|
// Create an ExifHelper to save the exif data that is lost during compression
|
||||||
ExifHelper exif = new ExifHelper();
|
ExifHelper exif = new ExifHelper();
|
||||||
if (realPath != null && this.encodingType == JPEG) {
|
|
||||||
try {
|
try {
|
||||||
exif.createInFile(realPath);
|
exif.createInFile(realPath);
|
||||||
exif.readExifData();
|
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
|
// 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.
|
// application cache I'm adding the current system time to the end of the file url.
|
||||||
this.callbackContext.success("file://" + modifiedPath + "?" + System.currentTimeMillis());
|
this.callbackContext.success("file://" + modifiedPath + "?" + System.currentTimeMillis());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
this.failPicture("Error retrieving image.");
|
this.failPicture("Error retrieving image.");
|
||||||
@ -1183,7 +1192,13 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
|
|||||||
takePicture(this.destType, this.encodingType);
|
takePicture(this.destType, this.encodingType);
|
||||||
break;
|
break;
|
||||||
case SAVE_TO_ALBUM_SEC:
|
case SAVE_TO_ALBUM_SEC:
|
||||||
|
this.getImage(this.srcType, this.destType, this.encodingType);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean fileWillBeModified() {
|
||||||
|
return (this.targetWidth > 0 && this.targetHeight > 0) ||
|
||||||
|
this.correctOrientation || this.allowEdit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user