navigator.camera.getPicture 回调直到第二次调用才执行 [英] navigator.camera.getPicture callback doesn't execute until 2nd call

查看:23
本文介绍了navigator.camera.getPicture 回调直到第二次调用才执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行cordova 3.1.0的phonegap(cordova)应用程序,当我打电话时

I've got a phonegap (cordova) app running cordova 3.1.0 and when I call

navigator.camera.getPicture(success,fail,options)

选项为

var options={ 
        destinationType: navigator.camera.DestinationType.FILE_URI,
        sourceType: navigator.camera.PictureSourceType.SAVEDPHOTOALBUM,
        encodingType: navigator.camera.EncodingType.JPEG,
        mediaType: navigator.camera.MediaType.Picture
}

在用户选择照片后不会调用成功回调.

the success callback isn't called after the photo is selected by the user.

如果我再打电话

navigator.camera.getPicture(success,fail,options)

再次使用第一步中选择的照片调用第一个 getPicture 的成功回调.

again, the success callback from the first getPicture is called with the photo selected in the first step.

我在 CameraLauncher.java 中(从第 395 行开始)四处寻找,似乎它调用了

I've poked around in CameraLauncher.java (around line 395 onwards) and it seems that it calls

this.callbackContext.success(uri.toString());

onActivtyResult 但这似乎直到下一次 getPicture() 调用才会传回.

onActivtyResult but this doesn't seem to be passed back until the next getPicture() call.

还有其他人遇到过这个吗?

Anybody else come across this?

进一步挖掘显示,当从相机调用 getPicture 时也会发生同样的事情.

Further digging shows the same thing happening when calling getPicture from camera too.

我想知道是不是因为当相机活动完成时 webview 没有恢复所以回调无处可去 - 但这充其量只是疯狂的猜测.

I'm wondering if it's because when the camera activity finishes the webview hasn't resumed so the callback has nowhere to go - but this is wild speculation at best.

24 小时后,似乎更新到 Cordova 3.1.0.jar 并将 3.1 jar 直接放入现有的 3.0 项目中解决了这个问题.

24 hours later, it seems that updating to Cordova 3.1.0.jar and dropping the 3.1 jar directly into an existing 3.0 project resolved this issue.

推荐答案

针对条形码扫描仪的类似问题,我尝试了此处记录的解决方案,并且奏效了.https://github.com/zeroasterisk/MeteorRider/issues/16(从这里引用:https://github.com/wildabeast/BarcodeScanner/issues/107)

I tried the solution documented here for a similar issue with the barcode scanner, and it worked. https://github.com/zeroasterisk/MeteorRider/issues/16 (as referred to from here: https://github.com/wildabeast/BarcodeScanner/issues/107)

总而言之,Android 事件管道似乎被堵塞"了,您可以在正常的cordova 插件调用之前运行此代码来清除它.

To summarize, it appears that the Android event pipeline gets "clogged", and you can run this code before your normal cordova plugin call to clear it.

if (device.platform === 'Android') {
  setInterval(function () {
     cordova.exec(null, null, '', '', [])
  }, 200);
}

这篇关于navigator.camera.getPicture 回调直到第二次调用才执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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