3

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.

durron597
  • 31,968
  • 17
  • 99
  • 158
davecozens
  • 83
  • 1
  • 6
  • OK. I updated Cordova to 3.1.0 and the problem went away. However, since I'm in a delicate timeframe and didn't want to kill my existing cordova projects I literally created a new project and copied Cordova-3.1.0.jar into my lib directory and removed 3.0.0 from same... Getting away with it so far... – davecozens Nov 06 '13 at 12:29
  • What full version of Cordova do you use? I use 3.1.0-0.15.0 and bug is not fixed in this version. – Volodymyr Bezuglyy May 29 '14 at 15:25
  • does anybody found a solution? I'm facing the same problem even with cordova 4.0.0 – ghost rider3 Oct 22 '14 at 16:32
  • are you solved this issue... – Aravin Dec 24 '14 at 07:33
  • With Cordova 5.1.0 experiencing the same issue with Android Jelly Bean 4.4.2 & 4.4.4. You mentioned callback triggered during second invoke, in my case this work around did not work as well. Here is my post http://stackoverflow.com/questions/37808733/cordova-navigator-camera-getpicture-not-working-in-android – Naga Jun 26 '16 at 16:13

2 Answers2

1

So, what was happening was that on Android only the callback for getPicture was being triggered by requesting getPicture a second time.

This was resolved by updating my cordova install, creating an empty android project and then copying the /platforms/android/libs/cordova-3.1.0.jar from it, into /platforms/android/libs in my existing project and removing cordova-3.0.0.jar

Hope this saves somebody an hour or 3...

davecozens
  • 83
  • 1
  • 6
  • having the same issue with Cordova 3.2 – Liron Harel Mar 27 '14 at 12:22
  • 3.4 same, and does not make callback at all on android. – Teoman shipahi May 22 '14 at 03:50
  • @VladimirBezugliy nope, works great on windows phone and not in android. I opened specific thread here for 3.4 http://stackoverflow.com/questions/23798076/cordova-3-4-0-navigator-camera-getpicture-does-not-callback-onsuccess-or-onfail/23800424?noredirect=1 – Teoman shipahi May 29 '14 at 17:03
  • I am experiencing same issue http://stackoverflow.com/questions/37808733/file-upload-from-android-to-windows-server-works-in-simulator-but-fails-in-devic – Naga Jun 24 '16 at 03:22
1

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);
}
  • This seems to have fixed the issue for many but did not work for me in Android Jelly Bean 4.4.2 & 4.4.4. Here is my post http://stackoverflow.com/questions/37808733/cordova-navigator-camera-getpicture-not-working-in-android – Naga Jun 26 '16 at 16:00