Having problem with ngCordova Camera Plugin

Hi There,

I am trying to get pic from phone camera and store into phone gallery using ionic framework.

For that i am using org.apache.cordova.camera

My application is working properly. It is able to take picture from camera and load into img tag on page.

I am only facing difficulty with the camera plugin option “saveToPhotoAlbum”.

when i make saveToPhotoAlbum to False then it is capturing image and i am getting image in the cache folder of application in android phone.

But when i make saveToPhotoAlbum to true then it is capturing image and storing it to gallary as well but also giving error in error callback that is “Error Capturing Image”. because of that i am unable to getting the path of captured image.

I am unable to find why i am getting this error. can any body help me to solve this problem.

My code is here:

Index.html

<div ng-controller="indexController">
    <ion-content>
            <div class="card">
                <div class="item item-divider">
                    Take a picture
                </div>
                <div class="item item-image">
                    <img id="imgbox" class="item" src="{{cameraService.cameraimage}}" style="height: 350px;"/>
                </div>
            </div>
    
            <div class="padding">
                <button class="button button-block button-positive" ng-click="cameraService.takePhoto()">
                    Take New Photo
                </button>
                <button class="button button-block button-positive" ng-click="cameraService.fetchPhoto()">
                    Get From Gallery
                </button>
            </div>
        </ion-content>
</div>

CameraService.js

 App.service('cameraService', function($cordovaCamera,$cordovaFile) {
        this.cameraimage;       

        this.getPhoto = function(SourceType) {
            var options = {
                quality: 50,
                destinationType: Camera.DestinationType.FILE_URI,
                sourceType: SourceType,
                saveToPhotoAlbum: true,
                encodingType: Camera.EncodingType.JPEG    
            };
    
            $cordovaCamera.getPicture(options).then(function(imageData) {
                console.log("img URI= " + imageData);
                var image = document.getElementById('imgbox');
                image.src = imageData;
            }, function(err) {
                 alert("Failed because: "+ err);
                console.log('Failed because: ' + err);
            });     
        };
           
        this.takePhoto = function(sourceType) {
            this.getPhoto(Camera.PictureSourceType.CAMERA);
        };
    
        this.fetchPhoto = function(SourceType) {
            this.getPhoto(Camera.PictureSourceType.SAVEDPHOTOALBUM);
        };
    });

IndexConroller.js

  App.controller('indexController', function($scope,cameraService) {
         $scope.cameraService=cameraService;
    });

I had also test this code in ios and it working without any error. i don’t know what is the problem with android.

Is you app closed after you are taking the photo?

Android sometimes close the app, that opens the camera to free memory for the camera.
So in somecases my Moto G and G (2. edition) gets closed when i open the camera.

Do not recognized this behavior if i use saveToPhotoAlbum true.
Is you app still open afterwards or does it a restart?

Greets.

No application is not closed after capturing image.
It is just giving error “Error Capturing Image” but actually image is already stored in gallery.

FWIW I had the exact same issue with version 0.3.6 of the plugin (the latest one).
Downgrading to 0.3.5 fixed the issue for me.

1 Like

Thx ! It works again with the downgrade.

Thanks it also fix for me

hie…
i am new to ionic . i amd using ng cordova camera and i want to set the image name clicked by camera. is dere any way ??? please help me out…
if is dere any example . please share

In my case I have this problem increasing either the quality or width and height of the picture. I just can use 20 of quality as maximun, very poor. I downgrade the pluging and still have the problem. Anyone can help me? thank you

@skyrocket777 in your camera plugin code add permission for allow edit as mentioned below

navigator.camera.getPicture(onSuccess, onFail, {
quality : 20,
sourceType : Camera.PictureSourceType.CAMERA,
destinationType : Camera.DestinationType.FILE_URI,
saveToPhotoAlbum: true,
encodingType: Camera.EncodingType.JPEG,
correctOrientation:true,
allowEdit: true
});

I am also getting error, i have checked with all device in android,

also checked uninstall and re-install the camera plugin, kindly help me

this the error :-

05-24 11:37:12.593: E/PluginManager(13986): Uncaught exception from plugin
05-24 11:37:12.593: E/PluginManager(13986): java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)’ on a null object reference
05-24 11:37:12.593: E/PluginManager(13986): at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:560)
05-24 11:37:12.593: E/PluginManager(13986): at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:534)
05-24 11:37:12.593: E/PluginManager(13986): at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:376)
05-24 11:37:12.593: E/PluginManager(13986): at org.apache.cordova.camera.CameraLauncher.takePicture(CameraLauncher.java:295)
05-24 11:37:12.593: E/PluginManager(13986): at org.apache.cordova.camera.CameraLauncher.callTakePicture(CameraLauncher.java:275)
05-24 11:37:12.593: E/PluginManager(13986): at org.apache.cordova.camera.CameraLauncher.execute(CameraLauncher.java:184)
05-24 11:37:12.593: E/PluginManager(13986): at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
05-24 11:37:12.593: E/PluginManager(13986): at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
05-24 11:37:12.593: E/PluginManager(13986): at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:57)
05-24 11:37:12.593: E/PluginManager(13986): at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
05-24 11:37:12.593: E/PluginManager(13986): at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
05-24 11:37:12.593: E/PluginManager(13986): at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:41)
05-24 11:37:12.593: E/PluginManager(13986): at android.os.Handler.dispatchMessage(Handler.java:111)
05-24 11:37:12.593: E/PluginManager(13986): at android.os.Looper.loop(Looper.java:207)
05-24 11:37:12.593: E/PluginManager(13986): at android.os.HandlerThread.run(HandlerThread.java:61)
05-24 11:37:12.606: D/PerfServiceManager(941): [PerfService] MESSAGE_TIMEOUT:103

My plugins --v:-
“cordova-plugin-camera”: “^2.4.1”,
“cordova-plugin-compat”: “^1.1.0”,

Hi , did you found any solution for this error?
I too have “cordova-plugin-camera”: “^2.4.1”,