javascript - DevExtreme/Phonegap camera plugin: "Cannot read propetry 'getPicture' of undefined" -
i'm getting crazy app.
i'm using devextreme, based on phonegap.
i'd take picture camera in app, have troubles.
first of all, here config.xml.
<widget id="com.devexpress.apptemplate" version="1.0" versioncode="1"> <name>applicationtemplate</name> <description>template</description> <preference name="permissions" value="none" /> <preference name="prerendered-icon" value="true" /> <preference name="android-windowsoftinputmode" value="adjustpan" /> <preference name="splashscreendelay" value="60000" /> <preference name="autohidesplashscreen" value="false" /> <preference name="splashshowonlyfirsttime" value="false" /> <preference name="fadesplashscreen" value="false" /> <preference name="showsplashscreenspinner" value="false" /> <preference name="disallowoverscroll" value="true" /> <preference name="statusbaroverlayswebview" value="false" /> <preference name="statusbarbackgroundcolor" value="#000000" /> <preference name="android-minsdkversion" value="14" /> <preference name="android-targetsdkversion" value="22" /> <plugin name="cordova-plugin-camera" spec="^2.4.1" source="npm" /> <plugin name="cordova-plugin-splashscreen" onload="true" /> <plugin name="cordova-plugin-whitelist" /> <plugin name="cordova-plugin-ios-longpress-fix" /> <plugin name="cordova-plugin-statusbar" onload="true" /> <access origin="*" /> </widget> do see wrong here?
further, have button call camera function (copied tutorial):
// called when photo retrieved // function onphotodatasuccess(imagedata) { try { // image handle // var smallimage = document.getelementbyid('smallimage'); // unhide image elements // smallimage.style.display = 'block'; // show captured photo // inline css rules used resize image // smallimage.src = "data:image/jpeg;base64," + imagedata; } catch (err) { alert(err.message); } } // called when photo retrieved // function onphotofilesuccess(imagedata) { // image handle console.log(json.stringify(imagedata)); // image handle // var smallimage = document.getelementbyid('smallimage'); // unhide image elements // smallimage.style.display = 'block'; // show captured photo // inline css rules used resize image // smallimage.src = imagedata; } // called when photo retrieved // function onphotourisuccess(imageuri) { // uncomment view image file uri // console.log(imageuri); // image handle // var largeimage = document.getelementbyid('largeimage'); // unhide image elements // largeimage.style.display = 'block'; // show captured photo // inline css rules used resize image // largeimage.src = imageuri; } // button call function // function capturephotowithdata() { try { // take picture using device camera , retrieve image base64-encoded string navigator.camera.getpicture(onphotodatasuccess, onfail, { quality: 50 }); } catch (err) { alert(err.message); } } function capturephotowithfile() { navigator.camera.getpicture(onphotofilesuccess, onfail, { quality: 50, destinationtype: camera.destinationtype.file_uri }); } // button call function // function getphoto(source) { debugger; // retrieve image file location specified source navigator.camera.getpicture(onphotourisuccess, onfail, { quality: 50, destinationtype: overviewapp.destinationtype.file_uri, sourcetype: source }); } // called if bad happens. // function onfail(message) { alert('failed because: ' + message); } and here related html:
[...] <div class="mybtnphoto" data-bind="dxbutton: { text: 'conferma con foto', onclick: capturephotowithdata}" style="float:right;"></div> [...] <img style="display:none;width:60px;height:60px;" id="smallimage" src="" /> <img style="display:none;" id="largeimage" src="" /> [...] the function capturephotowithdata correctly called, function goes in catch branch , alert shows "cannot read propetry 'getpicture' of undefined"
i create template , build solution. trying on android device. read lot of forum , other questions in web, nothing still worked me.
do see mistakes or missing here?
that means navigator.camera undefined project doesn't see cordova-plugin-camera.
the common issue can be: call before device ready. sure call camera deviceready:
document.addeventlistener("deviceready", function(){ console.log(navigator); // here can check plugins } you can run: $ cordova plugin list sure plugin exists in list.
also try rebuild: $ cordova build android ( or ios)
Comments
Post a Comment