mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-01-18 19:22:51 +08:00
fix(android): return error if file url is null (#632)
This commit is contained in:
parent
eb7fc333ee
commit
e2ecd7fe91
@ -686,68 +686,75 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
LOG.d(LOG_TAG, "File location is: " + fileLocation);
|
LOG.d(LOG_TAG, "File location is: " + fileLocation);
|
||||||
|
|
||||||
String uriString = uri.toString();
|
String uriString = uri.toString();
|
||||||
|
String finalLocation = fileLocation != null ? fileLocation : uriString;
|
||||||
String mimeType = FileHelper.getMimeType(uriString, this.cordova);
|
String mimeType = FileHelper.getMimeType(uriString, this.cordova);
|
||||||
|
|
||||||
// If you ask for video or the selected file doesn't have JPEG or PNG mime type
|
if (finalLocation == null) {
|
||||||
// there will be no attempt to resize any returned data
|
this.failPicture("Error retrieving result.");
|
||||||
if (this.mediaType == VIDEO || !(JPEG_MIME_TYPE.equalsIgnoreCase(mimeType) || PNG_MIME_TYPE.equalsIgnoreCase(mimeType))) {
|
} else {
|
||||||
this.callbackContext.success(fileLocation);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
// This is a special case to just return the path as no scaling,
|
// If you ask for video or the selected file doesn't have JPEG or PNG mime type
|
||||||
// rotating, nor compressing needs to be done
|
// there will be no attempt to resize any returned data
|
||||||
if (this.targetHeight == -1 && this.targetWidth == -1 &&
|
if (this.mediaType == VIDEO || !(JPEG_MIME_TYPE.equalsIgnoreCase(mimeType) || PNG_MIME_TYPE.equalsIgnoreCase(mimeType))) {
|
||||||
(destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation &&
|
this.callbackContext.success(finalLocation);
|
||||||
mimeType != null && mimeType.equalsIgnoreCase(getMimetypeForFormat(encodingType)))
|
}
|
||||||
{
|
else {
|
||||||
this.callbackContext.success(uriString);
|
|
||||||
} else {
|
|
||||||
Bitmap bitmap = null;
|
|
||||||
try {
|
|
||||||
bitmap = getScaledAndRotatedBitmap(uriString);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (bitmap == null) {
|
|
||||||
LOG.d(LOG_TAG, "I either have a null image path or bitmap");
|
|
||||||
this.failPicture("Unable to create bitmap!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If sending base64 image back
|
// This is a special case to just return the path as no scaling,
|
||||||
if (destType == DATA_URL) {
|
// rotating, nor compressing needs to be done
|
||||||
this.processPicture(bitmap, this.encodingType);
|
if (this.targetHeight == -1 && this.targetWidth == -1 &&
|
||||||
}
|
(destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation &&
|
||||||
|
mimeType != null && mimeType.equalsIgnoreCase(getMimetypeForFormat(encodingType)))
|
||||||
// If sending filename back
|
{
|
||||||
else if (destType == FILE_URI || destType == NATIVE_URI) {
|
this.callbackContext.success(finalLocation);
|
||||||
// Did we modify the image?
|
} else {
|
||||||
if ( (this.targetHeight > 0 && this.targetWidth > 0) ||
|
Bitmap bitmap = null;
|
||||||
(this.correctOrientation && this.orientationCorrected) ||
|
try {
|
||||||
!mimeType.equalsIgnoreCase(getMimetypeForFormat(encodingType)))
|
bitmap = getScaledAndRotatedBitmap(uriString);
|
||||||
{
|
} catch (IOException e) {
|
||||||
try {
|
e.printStackTrace();
|
||||||
String modifiedPath = this.outputModifiedBitmap(bitmap, uri);
|
|
||||||
// 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.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.callbackContext.success(fileLocation);
|
|
||||||
}
|
}
|
||||||
|
if (bitmap == null) {
|
||||||
|
LOG.d(LOG_TAG, "I either have a null image path or bitmap");
|
||||||
|
this.failPicture("Unable to create bitmap!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If sending base64 image back
|
||||||
|
if (destType == DATA_URL) {
|
||||||
|
this.processPicture(bitmap, this.encodingType);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If sending filename back
|
||||||
|
else if (destType == FILE_URI || destType == NATIVE_URI) {
|
||||||
|
// Did we modify the image?
|
||||||
|
if ( (this.targetHeight > 0 && this.targetWidth > 0) ||
|
||||||
|
(this.correctOrientation && this.orientationCorrected) ||
|
||||||
|
!mimeType.equalsIgnoreCase(getMimetypeForFormat(encodingType)))
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
String modifiedPath = this.outputModifiedBitmap(bitmap, uri);
|
||||||
|
// 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.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.callbackContext.success(finalLocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bitmap != null) {
|
||||||
|
bitmap.recycle();
|
||||||
|
bitmap = null;
|
||||||
|
}
|
||||||
|
System.gc();
|
||||||
}
|
}
|
||||||
if (bitmap != null) {
|
|
||||||
bitmap.recycle();
|
|
||||||
bitmap = null;
|
|
||||||
}
|
|
||||||
System.gc();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user