For testing purposes, I copied the full example found in the phone camera API , and I put a warning on onPhotoDataSuccess to check when the function quits. On the first photo taken, a warning will not be displayed. However, after the first attempt, a warning will be displayed after saving the photo.
Any tips? I will be happy to be more specific if something is unclear.
I checked the code below on my Android Galaxy S3
<!DOCTYPE html> <html> <head> <title>Capture Photo</title> <script type="text/javascript" charset="utf-8" src="cordova.js"></script> <script type="text/javascript" charset="utf-8"> var pictureSource; </script> </head> <body> <button onclick="capturePhoto();">Capture Photo</button> <br> <button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br> <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br> <button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br> <img style="display:none;width:60px;height:60px;" id="smallImage" src="" /> <img style="display:none;" id="largeImage" src="" /> </body> </html>
---------- UPDATE 1 ------------------
I tested it on another bit of code:
(function () { $scroller = $('.scroller'), // Take a picture using the camera or select one from the library takePicture = function (e) { var options = { quality: 45, targetWidth: 1000, targetHeight: 1000, destinationType: Camera.DestinationType.FILE_URI, encodingType: Camera.EncodingType.JPEG, sourceType: Camera.PictureSourceType.CAMERA }; navigator.camera.getPicture( function (imageURI) { console.log(imageURI); alert('test'); $scroller.append('<img src="' + imageURI + '"/>'); }, function (message) { // We typically get here because the use canceled the photo operation. Fail silently. }, options); return false; }; $('.camera-btn').on('click', takePicture); }());
And it has the same effect. It does nothing during the first snap, but shows the image after the second snap. I also only found out that the photo that shows after the second is the first photo I took. It seems that the first argument in getPicture does not work on the first binding. This is frustrating because logcat doesn't really show me anything to work with.
---------------- UPDATE 2 ----------------
I just tried this on Phonegap Build and it works. Therefore, it should have something to do with the plugin ...
javascript android cordova camera
Ian powder
source share