简体   繁体   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

I am using Cordova 3.4 with Camera Plugin ( https://github.com/apache/cordova-plugin-camera/blob/master/doc/index.md ) 我使用Cordova 3.4和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). 此代码适用于Windows Phone 8.1,但不适用于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. 当我在eclipse中进入代码时,我可以看到它在android临时目录下成功保存了照片,但是在完成时没有调用JavaScript成功或失败事件,这就是我无法在android上获取图像的原因。

I both tried on Galaxy Note 2 real device and emulator and did not call onSuccess on both. 我都试过Galaxy Note 2真实设备和模拟器,但两者都没有调用onSuccess。

Is there any known issues or workaround for this problem? 此问题是否存在任何已知问题或解决方法?

Try this options: 试试这个选项:

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

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). 他们的工作部署在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

        });

//reading and appending the DOM //阅读并附加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. 这将返回base64编码的图像。

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). 事实证明,我在应用程序的Cordova“暂停”事件中调用了“navigator.camera.cleanup()”(因此当应用程序被发送到后台时它会清理资源)。 The problem here was that the camera sends the app to the background, so apparently calling cleanup was breaking things. 这里的问题是相机将应用程序发送到后台,所以显然调用清理是破坏事情。

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

相关问题 cordova navigator.camera.getPicture 在 android 中不起作用 - cordova navigator.camera.getPicture not working in android navigator.camera.getPicture在android中不起作用 - navigator.camera.getPicture not working in android navigator.camera.getPicture不会调用成功回调 - 离子框架 - cordova - navigator.camera.getPicture doesn’t call success callback - ionic framework - cordova Cordova navigator.camera.getPicture在Android 4.4 KitKat上以意外格式返回FILE_URI - Cordova navigator.camera.getPicture returns FILE_URI in unexpected format on Android 4.4 KitKat from gallery 为什么我不能在Android应用中使用Cordova 2.7.0触发navigator.camera.getPicture? - Why can't I trigger navigator.camera.getPicture using Cordova 2.7.0 in my Android app? PhoneGap navigator.camera.getPicture不触发回调 - PhoneGap navigator.camera.getPicture don't trigger Callback navigator.camera.getPicture无法正常工作 - navigator.camera.getPicture not working properly 画廊错误中的navigator.camera.getPicture错误“无法创建位图” - navigator.camera.getPicture from the gallery error “Unable to create bitmap” navigator.camera.getPicture不打开设备的默认相机应用程序 - navigator.camera.getPicture dont opens the device's default camera application 如何使用Apache Cordova在Android中使用camera.getPicture? - How does camera.getPicture works in android using apache cordova?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM