Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
809 views
in Technique[技术] by (71.8m points)

cordova - navigator.camera.getPicture callback doesn't execute until 2nd call

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...