繁体   English   中英

Cordova 3.4.0 navigator.camera.getPicture不会为Android 4.3回调onSuccess或onFail

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

我使用Cordova 3.4和Camera Plugin( https://github.com/apache/cordova-plugin-camera/blob/master/doc/index.md

我打电话的时候

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);
}

此代码适用于Windows Phone 8.1,但不适用于Android 4.3(Jelly Bean)。 当我在eclipse中进入代码时,我可以看到它在android临时目录下成功保存了照片,但是在完成时没有调用JavaScript成功或失败事件,这就是我无法在android上获取图像的原因。

我都试过Galaxy Note 2真实设备和模拟器,但两者都没有调用onSuccess。

此问题是否存在任何已知问题或解决方法?

试试这个选项:

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

如果这不起作用,请让我建议这些选项。 他们的工作部署在4.2.2(Jellybean)android和4.4.2(Kitkat)上。

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

        });

//阅读并附加DOM

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

这将返回base64编码的图像。

如果它可以帮助任何人,我有同样的问题。 事实证明,我在应用程序的Cordova“暂停”事件中调用了“navigator.camera.cleanup()”(因此当应用程序被发送到后台时它会清理资源)。 这里的问题是相机将应用程序发送到后台,所以显然调用清理是破坏事情。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM