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

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

问题描述

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

  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
}

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



如果我随后调用

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

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



我在CameraLauncher中搜索过。 java(在395行左右),它似乎调用

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

onActivtyResult中的



任何人都遇到了这个问题?



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



我想知道是否是因为当相机活动完成时webview没有恢复,所以回调无处可去 - 但这是最​​好的野生推测。 / p>

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

解决方案

我试图解决这里的解决方案与条形码扫描器类似的问题,它的工作。 https://github.com/zeroasterisk/MeteorRider/issues/16
(如下所示: https://github.com/wildabeast/BarcodeScanner/issues/107



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

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


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

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

with options as

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.

If I then call

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

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

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

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

in

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

Anybody else come across this?

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

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 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.

解决方案

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)

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天全站免登陆