Callback navigator.camera.getPicture is not executed until the second call

I have a phonegap application (cordova) working with corridor 3.1.0, and when I call

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

with parameters

 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 is not called after the user has selected the photo.

If I call then

 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 poked in CameraLauncher.java (around line 395 onwards) and it seems like it is calling

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

in

onActivtyResult, but this does not seem to be passed back until the next call to getPicture ().

Anyone else come across this?

Further digging shows the same thing that happens when calling getPicture from the camera.

I’m interested, because when the camera’s activity ends, web browsing has not resumed, so there’s nowhere to go for a callback - but at best it’s a wild assumption.

After 24 hours, it seems that upgrading to Cordova 3.1.0.jar and dumping 3.1 bytes directly into an existing 3.0 project resolved this problem.

+3
source share
2 answers

So, it happened that on Android only the callback for getPicture was launched with the getPicture request a second time.

This was solved by updating my cordova installation, creating an empty Android project and then copying / platforms / android / libs / cordova -3.0.0.jar from it to / platform / android / lib in my existing project and removing cordova-3.0.0 .jar

Hope this saves someone an hour or 3 ...

+1
source

I tried the solution registered here for a similar problem with a barcode scanner, and it worked. https://github.com/zeroasterisk/MeteorRider/issues/16 (as mentioned here: https://github.com/wildabeast/BarcodeScanner/issues/107 )

To summarize, it seems that the Android event pipeline is getting "clogged", and you can run this code before your regular plugin call plugins clear it.

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

Source: https://habr.com/ru/post/969681/


All Articles