Can't select imagem from Camera in Android - Always "canceled"

I have this problem, every time I try select a picture straight from the Camera I always get an error “Camera cancelled.”.

The scenario: my user can select between get the picture from the Camera or Gallery, when the picture comes from the gallery everything works fine, but when it comes from Camera always go to the “error” function and prints that message on console.

The problem happens after selecting the area to cut and press button “Save” on camera app on Android.

Here is my code in the controller to get the picture and set on an image tag:

var openCamera = function(source){
var _sourceType = source===1 ? Camera.PictureSourceType.PHOTOLIBRARY : Camera.PictureSourceType.CAMERA;
var options = {
    quality: 50,
    destinationType: Camera.DestinationType.DATA_URL,
    // destinationType: Camera.DestinationType.FILE_URI,
    sourceType: _sourceType,
    allowEdit: true,
    encodingType: Camera.EncodingType.PNG,
    targetWidth: 180,
    targetHeight: 220,
    cameraDirection: 1, //Back = 0, Front-facing = 1
    popoverOptions: CameraPopoverOptions,
    saveToPhotoAlbum: false,
    correctOrientation:true
};

$cordovaCamera.getPicture(options).then(function(imageData) {
    savePicture(imageData);
}, function(err) {
    // Every time I get the picture directly from the camera it comes here
    $scope.profileImageData = APP_CONST.DEFAULT_IMG_DATA;
    console.log(JSON.stringify(err));
});

}; // openCamera

The config:

app.config(function($compileProvider){
    $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|geo|mailto|tel|chrome-extension):/);
    $compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|blob|content):|data:image\//);
})

Any help please?

Same issue I have the edit option enable but I get the “camera cancelled” error if I dont edit the image. If I edit the image it works fine. Anybody had the same issue?

H

Can you’re calling the method twice openCamera.

It is not the case, the problem is “the image captured is so big that I have a memory break” and app stops.

Hi, is there any solution for the error occured “camera cancelled”.??

This did it for me: <preference name=“AndroidLaunchMode” value=“standard” />
Add the above to config.xml

1 Like