科尔多瓦:camera.getPicture失败,并显示"Camera Cancelled". [英] Cordova: camera.getPicture fails with "Camera cancelled"

查看:136
本文介绍了科尔多瓦:camera.getPicture失败,并显示"Camera Cancelled".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个cordova应用程序(cli-5.2.0),其中的照片是使用cordova相机插件(cordova-plugin-camera,版本1.2.0)拍摄的.

I'm developing a cordova app (cli-5.2.0) in which pictures are taken using the cordova camera plugin (cordova-plugin-camera, version 1.2.0).

var camera = navigator.camera;
var cameraOptions = { 
  destinationType: Camera.DestinationType.DATA_URL
};

camera.getPicture(function(result) {
    alert('success');
  }, function(error) {
    alert('fail ' + error);
  }, cameraOptions);

此代码在大多数情况下都可以正常工作.
在特定的速度较慢的android 4.4.4设备上,这只能正常工作,十分之九.
在10分之一中,呼叫失败时显示摄像机已取消"(尽管并未使用后退"按钮或其他按钮取消).

This code works fine.. ..most of the time.
On a particular slow android 4.4.4 device, this only works fine like 9 out of 10 times.
In like 1 out of 10, the call fails saying 'Camera cancelled' (although it was not cancelled with the back button or something).

在这种情况下,将触发失败回调"Camera cancelled",然后立即显示Camera UI.
(如果拍照,则不会调用成功回调).

In that case, the failure callback 'Camera cancelled' is fired, and right after that, the Camera UI is shown nevertheless.
(if a picture is taken then, the success callback is not called).

很难确定何时会发生这种情况,但是如果设备上的应用更加繁忙,则看起来这种情况会更频繁地发生.
日志文件没有显示更多详细信息,除了以下内容外:

It's hard to tell when this happens, but it looks like it happens more often if the device is app is more busy.
The log files do not show much more detail, except for things like:

尝试发送ID为以下内容的第二个回调:Camera1337050609

Attempted to send a second callback for ID: Camera1337050609

但是,如果调用成功,也会记录这些日志.

However, these logs are also written if the call succeeds.


非常感谢任何提示或帮助.

谢谢您的宝贵时间
科恩


Any hints or help is much appreciated.

Thanks for your time,
Koen

更新1 (回答评论)

ProjectDetailCtrl.prototype.takePhoto = function () {
    var _this = this;
    // this cameraService calls the code from above
    return this.cameraService.getPicture()
        .then(function (imageData) {
            _this.$log.debug('got camera data');
            // ..
        },

<!-- This is an angular application, the click handling goes like: -->
<md-button ng-click="vm.takePhoto()">
    Add photo
</md-button>

推荐答案

我已经看到此问题在2种情况下发生-1)@Joerg已经提到过,内存不足,2)事件被级联,并被触发两次.例如,您在div内有一个Icon的onClick,还具有另一个事件触发器,例如a-href或另一个onClick.

I have seen this problem occur under 2 conditions - 1) Low memory as what @Joerg has already mentioned, 2) Your events are cascaded, and are triggered twice. For instance, you have a onClick on an Icon, inside a div that also has another event trigger like an a-href or another onClick.

如果您可以发布代码,则可能会有所帮助.

If you can post your code, it might help.

更新-1: 绝对表示内存不足的情况.在这里危险的猜测... 1.发生对摄像机的紧急呼叫 2.内存不足会返回相机取消故障事件 3.相机在有足够的可用存储空间时会稍后打开 4.摄像机成功事件无法找到该回调,因为在较早的失败事件之后该回调已被清除,从而导致第二个回调"情况

Update - 1: Definitely indicates a low memory situation. Hazarding a guess here... 1. Asynch call to Camera occurs 2. Low memory returns a Camera cancelled failure event 3. Camera does open later when enough free memory is available 4. Camera success event is not able to find the callback as the callback is already cleared after the earlier failure event, resulting in 'Second callback' scenario

现在,您每次使用完全相同的照片/视频都会遇到此问题吗?

Now, do you have this problem with the exact same photo/video each time?

您可能会避免的方法是-不将呼叫与".then"链接在一起,而是实际执行常规的异步回调.

The way you can probably avoid this is - not chain the call with a ".then" but actually do a regular async callback.

此外,您可能想检查并防止相机服务"的任何较早调用完成.

Also, you might want to check and guard against any earlier invocation of the 'camera service' is finished.

这篇关于科尔多瓦:camera.getPicture失败,并显示"Camera Cancelled".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆