Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement stop() to close CAMERA or PHOTOLIBRARY #873

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/android/CameraLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ else if ((this.srcType == PHOTOLIBRARY) || (this.srcType == SAVEDPHOTOALBUM)) {
r.setKeepCallback(true);
callbackContext.sendPluginResult(r);

return true;
} if (action.equals("stop")) {
this.stopCamera(destType);
return true;
}
return false;
Expand Down Expand Up @@ -352,6 +355,16 @@ public void takePicture(int returnType, int encodingType)
// LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
}

public void stopCamera(int returnType) {
LOG.d(LOG_TAG,"Stopping Camera");
try {
this.cordova.getActivity().finishActivity((CAMERA + 1) * 16 + returnType + 1);
this.cordova.getActivity().finishActivity((PHOTOLIBRARY + 1) * 16 + returnType + 1);
} catch(Exception e) {
LOG.e(LOG_TAG, "Error in closing Camera/Picker");
}
}

/**
* Create a file in the applications temporary directory based upon the supplied encoding.
*
Expand Down
1 change: 1 addition & 0 deletions src/ios/CDVCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ typedef NSUInteger CDVMediaType;
*/
- (void)takePicture:(CDVInvokedUrlCommand*)command;
- (void)cleanup:(CDVInvokedUrlCommand*)command;
- (void)stop:(CDVInvokedUrlCommand*)command;
- (void)repositionPopover:(CDVInvokedUrlCommand*)command;

- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info;
Expand Down
10 changes: 10 additions & 0 deletions src/ios/CDVCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ - (void)takePicture:(CDVInvokedUrlCommand*)command
}];
}

- (void)stop:(CDVInvokedUrlCommand*)command {
if (self.pickerController) {
NSLog(@"Closing Camera/Photo Library");
[self.pickerController dismissViewControllerAnimated:YES completion:^{
self.hasPendingOperation = NO;
self.pickerController = nil;
}];
}
}

- (void)showCameraPicker:(NSString*)callbackId withOptions:(CDVPictureOptions *) pictureOptions
{
// Perform UI operations on the main thread
Expand Down
7 changes: 7 additions & 0 deletions www/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ cameraExport.getPicture = function (successCallback, errorCallback, options) {
// return new CameraPopoverHandle();
};

/**
* Closes the Camera on calling this method
*/
cameraExport.stop = function (successCallback, errorCallback) {
exec(successCallback, errorCallback, 'Camera', 'stop', []);
};

/**
* Removes intermediate image files that are kept in temporary storage
* after calling [`camera.getPicture`]{@link module:camera.getPicture}. Applies only when the value of
Expand Down