android - Saving image to SD Card in a Worklight application -
i have created worklight application , added android environment. application has button take photo using device camera, , img tag in html displays captured photo.
i followed phonegap camera api.
now trying store image sd card fail doing so.
edit: changed code below:
function takeimage() { // retrieve image file location specified source navigator.camera.getpicture(getimageuri, function(message) { alert('image capture failed'); }, { quality : 40, destinationtype : camera.destinationtype.file_uri }); } function getimageuri(imageuri) { var gotfileentry = function(fileentry) { var img=document.getelementbyid("thisimage"); img.style.visiblity="visible"; img.style.display="block"; img.src=imageuri; alert("got image file entry: " + fileentry.fullpath); var gotfilesystem = function(filesystem){ // copy file fileentry.moveto(filesystem.root, "pic.jpg", null, null); }; // file system copy or move image file window.requestfilesystem(localfilesystem.persistent, 0, gotfilesystem, fsfail); }; //resolve file system image window.resolvelocalfilesystemuri(imageuri, gotfileentry, fsfail); } //file system fail function fsfail(error) { alert("failed error code: " + error.code); } everything working fine(capturing image , image available in app cache folder) except moveto method. fileentry.moveto(filesystem.root, "pic.jpg", null, null); put filesystem.root in alert , getting object object. folder location not available move image(and think real problem).
this, in fact, has got nothing worklight.
since using apache cordova access device's camera snap photo, should use store image file device's sd card.
here couple of questions point right solution you:
- how move captured image in phonegap folder in sdcard
- capturing , storing picture taken camera local database / phonegap / cordova / ios
note #1: link phonegap camera api points v1.0. worklight 5.0.6.x uses phonegap 2.3.0, sure use correct api version.
note #2: make sure have added permission write sd card adding below line android.manifest file:
<uses-permission android:name="android.permission.write_external_storage" /> note #3: in case #2 above not enough, try getting sd card location this:
file sddir = environment.getexternalstoragedirectory();
Comments
Post a Comment