It seems that the device object is undefined on Android. It is defined in the simulator, the iOS device & iOS simulator
Obviously I'm checking to see the window.device (and tried all variants of Window.device, window.Device, etc.), and always getting undefined -- but only on a real Android device. It works fine on all other scenarios.
Please help.
When are you trying to use window.device?
I found that on Android when "ondeviceready" is fired the window.device variable isn't available yet.
So what I did was set a timeout of 1 second after "ondeviceready" is fired and then do all the stuff I want to do.
My problem was that even though my plugins folder had the org.apache.cordova.device plugin folder listed, and it was referenced in the config.xml. I still couldn't get it to find window.device (or just device) when onDeviceReady was fired (or anywhere else for that matter)
How I managed to fix it was to run $ cordova plugin add cordova-plugin-device
again, expecting a 'plug-in already installed' message but it actually installed into the org.apache.cordova.device folder and then everything just worked.
My folder wasn't empty so I'm not sure why this worked and I'm a little concerned about what will happen when I deploy via phonegap-build but using $ cordova run android
, it now works perfectly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With