Cordova 3.4.0 navigator.camera.getPicture does not call onSuccess or onFail callback for Android 4.3

I am using Cordova 3.4 with a plugin for the camera ( 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 enter the code in eclipse, I see that it successfully saves the photo in the android temp directory, but does not cause JavaScript to complete or the event to end, so I can not get the image on Android.

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

Are there any known issues or workarounds for this issue?

+6
source share
3 answers

Try the following options:

 destinationType: navigator.camera.DestinationType.FILE_URI sourceType: source mediaType: media 
0
source

If this does not work, let me suggest these options. They work 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 }); 

// read and add 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
source

If this helps someone, I had the same problem. It turned out that I called "navigator.camera.cleanup ()" in the pause event in the application Cordoba (so that it would clear resources when the application was sent to the background). The problem was that the camera was sending the app to the background, so apparently the cleanup call was a violation.

0
source

Source: https://habr.com/ru/post/969676/


All Articles