This commit is contained in:
ldeluca 2014-07-07 11:07:15 -04:00
commit 08acf7bc49
4 changed files with 18 additions and 56 deletions

View File

@ -33,7 +33,7 @@ base64-encoded `String`, or as the URI for the image file. The method
itself returns a `CameraPopoverHandle` object that can be used to itself returns a `CameraPopoverHandle` object that can be used to
reposition the file selection popover. reposition the file selection popover.
navigator.camera.getPicture( cameraSuccess, cameraError, [ cameraOptions ] ); navigator.camera.getPicture( cameraSuccess, cameraError, cameraOptions );
### Description ### Description

29
src/android/CameraLauncher.java Executable file → Normal file
View File

@ -380,14 +380,19 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
else if (destType == FILE_URI || destType == NATIVE_URI) { else if (destType == FILE_URI || destType == NATIVE_URI) {
if (this.saveToPhotoAlbum) { if (this.saveToPhotoAlbum) {
Uri inputUri = getUriFromMediaStore(); Uri inputUri = getUriFromMediaStore();
//Just because we have a media URI doesn't mean we have a real file, we need to make it try {
uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova))); //Just because we have a media URI doesn't mean we have a real file, we need to make it
uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova)));
} catch (NullPointerException e) {
uri = null;
}
} else { } else {
uri = Uri.fromFile(new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg")); uri = Uri.fromFile(new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg"));
} }
if (uri == null) { if (uri == null) {
this.failPicture("Error capturing image - no media storage found."); this.failPicture("Error capturing image - no media storage found.");
return;
} }
// If all this is true we shouldn't compress the image. // If all this is true we shouldn't compress the image.
@ -420,14 +425,14 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
exif.writeExifData(); exif.writeExifData();
} }
if (this.allowEdit) { if (this.allowEdit) {
performCrop(uri); performCrop(uri);
} else { } else {
// Send Uri back to JavaScript for viewing image // Send Uri back to JavaScript for viewing image
this.callbackContext.success(uri.toString()); this.callbackContext.success(uri.toString());
} }
} }
// Send Uri back to JavaScript for viewing image } else {
this.callbackContext.success(uri.toString()); throw new IllegalStateException();
} }
this.cleanup(FILE_URI, this.imageUri, uri, bitmap); this.cleanup(FILE_URI, this.imageUri, uri, bitmap);
@ -641,7 +646,7 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
// If retrieving photo from library // If retrieving photo from library
else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK && intent != null) {
this.processResultFromGallery(destType, intent); this.processResultFromGallery(destType, intent);
} }
else if (resultCode == Activity.RESULT_CANCELED) { else if (resultCode == Activity.RESULT_CANCELED) {
@ -735,11 +740,11 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
Uri uri; Uri uri;
try { try {
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} catch (UnsupportedOperationException e) { } catch (RuntimeException e) {
LOG.d(LOG_TAG, "Can't write to external media storage."); LOG.d(LOG_TAG, "Can't write to external media storage.");
try { try {
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
} catch (UnsupportedOperationException ex) { } catch (RuntimeException ex) {
LOG.d(LOG_TAG, "Can't write to internal media storage."); LOG.d(LOG_TAG, "Can't write to internal media storage.");
return null; return null;
} }

View File

@ -84,7 +84,6 @@ typedef NSUInteger CDVMediaType;
* quality: integer between 1 and 100 * quality: integer between 1 and 100
*/ */
- (void)takePicture:(CDVInvokedUrlCommand*)command; - (void)takePicture:(CDVInvokedUrlCommand*)command;
- (void)postImage:(UIImage*)anImage withFilename:(NSString*)filename toUrl:(NSURL*)url;
- (void)cleanup:(CDVInvokedUrlCommand*)command; - (void)cleanup:(CDVInvokedUrlCommand*)command;
- (void)repositionPopover:(CDVInvokedUrlCommand*)command; - (void)repositionPopover:(CDVInvokedUrlCommand*)command;

View File

@ -533,48 +533,6 @@ static NSSet* org_apache_cordova_validArrowDirections;
return newImage; return newImage;
} }
- (void)postImage:(UIImage*)anImage withFilename:(NSString*)filename toUrl:(NSURL*)url
{
self.hasPendingOperation = YES;
NSString* boundary = @"----BOUNDARY_IS_I";
NSMutableURLRequest* req = [NSMutableURLRequest requestWithURL:url];
[req setHTTPMethod:@"POST"];
NSString* contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[req setValue:contentType forHTTPHeaderField:@"Content-type"];
NSData* imageData = UIImagePNGRepresentation(anImage);
// adding the body
NSMutableData* postBody = [NSMutableData data];
// first parameter an image
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"upload\"; filename=\"%@\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Type: image/png\r\n\r\n" dataUsingEncoding : NSUTF8StringEncoding]];
[postBody appendData:imageData];
// // second parameter information
// [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// [postBody appendData:[@"Content-Disposition: form-data; name=\"some_other_name\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// [postBody appendData:[@"some_other_value" dataUsingEncoding:NSUTF8StringEncoding]];
// [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r \n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[req setHTTPBody:postBody];
NSURLResponse* response;
NSError* error;
[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
// NSData* result = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
// NSString * resultStr = [[[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding] autorelease];
self.hasPendingOperation = NO;
}
- (CLLocationManager *)locationManager { - (CLLocationManager *)locationManager {
if (locationManager != nil) { if (locationManager != nil) {