Cordova Device Plugin Not Working

2,158 views
Skip to first unread message

Rachel Rinaldi

unread,
Apr 20, 2014, 4:21:16 PM4/20/14
to phon...@googlegroups.com
This may be a simple mistake but I cannot figure it out.

I added the Cordova device plugin through the CLI.

cordova plugin add https://git-wip-us.apache.org/repo
s/asf/cordova-plugin-device.git
Fetching plugin "https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.g
it" via git clone
Starting installation of "org.apache.cordova.device" for android
Preparing android project
org.apache.cordova.device installed on android.

I then issued a build on the project for android

 
cordova build android
Generating config.xml from defaults for platform "android"
Preparing android project
Compiling app on platform "android" via command "cmd" /c C:\Users\Rachel\StoneCr
eek\platforms\android\cordova\build
Platform "android" compiled successfully.

 Loaded up eclipse, no errors and I see the Cordova device plugin as a package in the src folder.  

Coded the line "var platform = device.platform;" in my app and the error: 'Uncaught ReferenceError: device is not defined at file'

Any ideas as to where I went wrong? This is on Cordova 3+

Rahul

unread,
Apr 21, 2014, 2:09:07 PM4/21/14
to phon...@googlegroups.com
Call the method on device ready listener.
document.addEventListener("deviceready",onDeviceReady,false);

function onDeviceReady(){
 alert
("Device Platform = "+device.platform);
}
Reply all
Reply to author
Forward
0 new messages