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

谁说胖子不能爱 提交于 2019-12-08 19:37:38

问题


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?


回答1:


Try this options:

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



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/23798076/cordova-3-4-0-navigator-camera-getpicture-does-not-callback-onsuccess-or-onfail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!