cordova - Capture functionality on HTML mode, what's missing? -
getting acquainted phonegap, stumbled error cannot assess (or can, sort of).
so want make html page button allows capture image (with mobile) using device camera, nothing fancy suppose.
i took essential of code phonegap's documentation, , here's page looks :
<!doctype html> <html> <head> <title>capture image</title> <script type="text/javascript" charset="utf-8" src="plugin_loader.js"></script> <script type="text/javascript" charset="utf-8" src="json2.js"></script> <script type="text/javascript" charset="utf-8"> // called when capture operation finished // function capturesuccess(mediafiles) { var i, len; (i = 0, len = mediafiles.length; < len; += 1) { uploadfile(mediafiles[i]); } } // called if bad happens. // function captureerror(error) { var msg = 'an error occurred during capture: ' + error.code; navigator.notification.alert(msg, null, 'uh oh!'); } // button call function // function captureimage() { // launch device camera application, // allowing user capture 2 images navigator.device.capture.captureimage(capturesuccess, captureerror, {limit: 2}); } // upload files server function uploadfile(mediafile) { var ft = new filetransfer(), path = mediafile.fullpath, name = mediafile.name; ft.upload(path, "http://my.domain.com/upload.php", function(result) { console.log('upload success: ' + result.responsecode); console.log(result.bytessent + ' bytes sent'); }, function(error) { console.log('error uploading file ' + path + ': ' + error.code); }, { filename: name }); } </script> </head> <body> <button onclick="captureimage();">capture image</button> <br> </body> </html>
trying out (on computer), following errors :
xmlhttprequest cannot load file:///c:/users/toshiba/desktop/test%20camera/cordova_plugins.json. cross origin requests supported http.
uncaught typeerror: cannot read property 'capture' of undefined
the first error related cordova_plugins.json isn't there, , in fact isn't. understood : need use phonegap the cordova js (which in case plugin_loader.js, bit modified on recommendations found on internet problem, didn't work...).
the second error related following line :
navigator.device.capture.captureimage(capturesuccess, captureerror, {limit: 2});
but normal guess on computer, not device in "mobile sense".
i've made trial on 2 mobile devices, failure follows.
i have js files, question following : necessary develop phonegap html5 , compile other specific platform native file thing work? hope not, because want work in web-app mode, or problem related missing files, if : can find surest functioning cordova js file ?
edit : think on computer, failure has navigator cannot retrieve device specifications , (thus) camera functionality (?!), that's on computer can case on mobiles (mobile's navigator having same issue).
i hope bear me new this, , in advance.
the cleanest answer found problem not technical, rather "categorical" 1 : can't use phonegap on html5 in sense cannot leave html. write on html5 build (and have build) native plateform format (.apk example).
otherwise, found there methods can exploit handles media capabilities html5, no doubt takes bit or developement, it's still start.
Comments
Post a Comment