Search code examples
androidcordovasencha-touch-2

device is not defined


Using an existing sencha project and PhoneGap Build, I have the problem that window.device is not defined if I query for it in the microloader/testing.js code.

Ext.blink = function(options) {
    ...
    Ext.microloaded = true;
    // Start my microloader enhancement
    isPhonegap = typeof window.device != "undefined";
    window.alert("isPhonegap: " + isPhonegap);

The config.xml contains the plugin:

<gap:plugin name="org.apache.cordova.device" />

Sencha is uploading everything to PhoneGap Build for me, it is built there, and then I download and adb install -r the resulting apk on my Android 4.0.4 Smartphone.

Result when starting the app, is the alert: isPhonegap: false.

What is the problem here?


Solution

  • Guessing a bit here, but could it be that you're calling that code before deviceReady has fired?

    See http://docs.phonegap.com/en/4.0.0/cordova_events_events.md.html#deviceready for details.