0

I have a kendoui applbuilder mobile app. I have installed a custom camerapreview plugin and it works fine. I tried adding an event handler to my view (afterShow) to set something in the camera plugin module:

cordova.plugins.camerapreview.startCamera(

which initializes the camera preview.

the problem seems to be that in this handler cordova.plugins.camerapreview is undefined? Access to this same method in a button handler on the view works fine. I'm assuming this has something to do with dependency? How can i ensure this is loaded? Doesn't make sense to me that it wouldn't be available after the view has loaded and bound the model.

my code looks like:

// Handle "deviceready" event
document.addEventListener('deviceready', onDeviceReady, false);


var mobileApp = new kendo.mobile.Application(document.body, {

                                                 skin: 'flat',
                                                 initial: 'views/home.html'
                                             });
billy jean
  • 1,399
  • 4
  • 25
  • 45

1 Answers1

1

When using Kendo UI Mobile app with Cordova, make sure to initialize the app in the deviceready event. This will ensure that the Cordova APIs will be available throughout the whole app lifecycle.

// this function is called by Cordova when the application is loaded by the device
document.addEventListener('deviceready', function () {  

  // hide the splash screen as soon as the app is ready. otherwise
  // Cordova will wait 5 very long seconds to do it for you.
  navigator.splashscreen.hide();

  app = new kendo.mobile.Application(document.body, {

    // you can change the default transition (slide, zoom or fade)
    transition: 'slide',

    // comment out the following line to get a UI which matches the look
    // and feel of the operating system
    // skin: 'flat',

    // the application needs to know which view to load first
    initial: 'views/home.html'
  });

}, false);
Bundyo
  • 2,195
  • 13
  • 13
  • initialize it IN the deviceready? Telerik has told me "you instantiate your Kendo UI Mobile Application before the deviceready event". It's not totally clear what this means as the deviceready event is fired whether i handle it or not. And it would seem WHERE the handler exists in relations to my app initialization statement wouldn't really matter? What am i missing? made an edit above. – billy jean Mar 12 '15 at 12:39
  • deviceready is a Cordova event which is fired whenever Cordova APIs are ready to use. So, in order to have the Cordova APIs ready in the Kendo UI Mobile events, you need to init the app when they are available and only way to be sure of that is IN the deviceready event. As an example, just create a new AppBuilder Kendo UI TabStrip project and check the deviceready event in app.js. I've posted it in my answer above. – Bundyo Mar 13 '15 at 16:09