6

I am using Cordova 3.4 with Camera Plugin (https://github.com/apache/cordova-plugin-camera/blob/master/doc/index.md)

When I call

navigator.camera.getPicture(onSuccess, onFail, {
        quality: 75,
        destinationType: window.Camera.DestinationType.FILE_URI,
        sourceType: window.Camera.PictureSourceType.CAMERA,
        //allowEdit: true,
        //cameraDirection: window.Camera.Direction.FRONT,
        //encodingType: window.Camera.EncodingType.JPEG,
        //targetWidth: 100,
        //targetHeight: 100,
        //popoverOptions: window.CameraPopoverOptions,
        saveToPhotoAlbum: true
    });
function onSuccess(imageData) {
    alert(imageData);
}
function onFail(message) {
    alert('Failed because: ' + message);
}

this code works for Windows Phone 8.1 but does not work for Android 4.3 (Jelly Bean). When I step into code in eclipse I can see that it successfully saves photo under android temp directory but does not call JavaScript success or fail event on complete, that's why I cannot get image on android.

I both tried on Galaxy Note 2 real device and emulator and did not call onSuccess on both.

Is there any known issues or workaround for this problem?

Teoman shipahi
  • 47,454
  • 15
  • 134
  • 158
  • Please check http://stackoverflow.com/questions/23653961/cordova-plugin-callback-received-after-second-plugin-call. Do you start your application in fullscreen mode? – Volodymyr Bezuglyy May 29 '14 at 17:11
  • @Teoman Is this issue fixed? I am also facing the same issue with cordova 3.5 – Konza Dec 10 '14 at 16:33
  • are you solved this issue.. – Aravin Dec 24 '14 at 07:30
  • @Aravin I believe it is not resolved yet because I see people has problem with cordova 3.5. Anyway I dropped using PhoneGap anymore I am switching gear to native & xamarin, hope Cordova will make a release to fix this problem. – Teoman shipahi Dec 24 '14 at 18:44
  • @Teomanshipahi Thanks for your reply...i solved this issue ...using this one http://stackoverflow.com/questions/19809164/navigator-camera-getpicture-callback-doesnt-execute-until-2nd-call/26166831#26166831 – Aravin Dec 25 '14 at 05:55
  • With cordova 5.1 & camera plugin 1.1.2 I am having same issue with Jelly Bean 4.4.2 & 4.4.4 still no clue how to fix this issue. Here is my post http://stackoverflow.com/questions/37808733/cordova-navigator-camera-getpicture-not-working-in-android – Naga Jun 26 '16 at 15:57

3 Answers3

0

Try this options:

destinationType: navigator.camera.DestinationType.FILE_URI
sourceType: source
mediaType: media
Xcihnegn
  • 11,579
  • 10
  • 33
  • 33
0

If this isn't working, let me suggest these options. They're working as deployed on 4.2.2 (Jellybean) android and 4.4.2 (Kitkat).

navigator.camera.getPicture(this.onPhotoDataSuccess, this.onFail, {
            quality: 50,
            destinationType: Camera.DestinationType.DATA_URL,
            sourceType: Camera.PictureSourceType.CAMERA

        });

//reading and appending the DOM

onPhotoDataSuccess(imageData) {
        var smallImage = document.getElementById('smallImage');
        smallImage.style.display = 'block';
        smallImage.src = "data:image/jpeg;base64," + imageData;
    }

This will return a base64 encoded image.

0

If it helps anyone, I had this very same issue. It turned out that I was calling "navigator.camera.cleanup()" in the Cordova "pause" event of the app (so it would clean up resources when the app was sent to the background). The problem here was that the camera sends the app to the background, so apparently calling cleanup was breaking things.

th317erd
  • 304
  • 3
  • 11