Clint C.
Clint C.

Reputation: 688

PhoneGap camera not working after build - Android

I've been making an app that makes use of the camera using phonegap. When I test the app through my device via eclipse the app launches and everything works great on my phone.

Once I run the phoneGap build service and download and test the app, everything works great except clicking on capture photo or get from library doesn't do anything. Any ideas why it would work before the build, but not after it?

code removed

Upvotes: 0

Views: 1353

Answers (2)

Xalior
Xalior

Reputation: 141

Clint,

First, a why: I suspect the reason that you were seeing a difference between actual build packages from Phonegap and the results from Eclipse is that your local build will be "slower" (due to debugging information in the package, or extra weight on the android device because of the adb process from eclipse... etc.) this is thus giving the DOM time to complete before the JS thread tries to seek those elements via jQuery.

As you worked out, the "correct way" to handle this would be to keep your external var definitions where they are...

// buttons for capturing and browsing for photo and uploading
        var capture_btn;   //     = $('#capture');     \
        var getImg_btn;    //     = $('#getImg');       >  do these later.
        var uploadImg_btn; //     = $('#uploadImg');   /

And then...

function onDeviceReady() {
    // now allocate DOM to buttons
        capture_btn    = $('#capture');    //
        getImg_btn     = $('#getImg');     // 'var'less, to keep in global scope
        uploadImg_btn  = $('#uploadImg');  //
    // rest of deviceReady as already written

You obviously "got it working" (YAY!) but hopefully this explains (with a wee bit more detail) why you were seeing differing results between live APKs and a local debugbuild and this fuller answer will help others in the future... :)

-TTFN and happy hacking,

Dx :)

Upvotes: 2

Clint C.
Clint C.

Reputation: 688

Turns out the answer was simple. My variables for camera functions were called before the DOM loaded them.

// buttons for capturing and browsing for photo and uploading
        var capture_btn    = $('#capture');
        var getImg_btn     = $('#getImg');
        var uploadImg_btn  = $('#uploadImg');

So it never even registered the clicks. Weird part is that it worked when testing through eclipse.

I added all of my camera controls into the deviceready event and viola. It works as it should.

Upvotes: 1

Related Questions