Cordova device plugin not working
12,261
Solution 1
Add this cordova pluign using this commend :
cordova plugin add cordova-plugin-device
Try this
<html>
<head>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
//add event listener
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(device); // device object
console.log(device.name); // Gives the name of device.
console.log(device.uuid ); // Gives the UUID.
}
</script>
</head>
<body>
</body>
</html>
Solution 2
Try this
<html>
<head>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
//add event listener
document.addEventListener("deviceready", onDeviceReady, false);
//device.name -> Gives the name of device.
//device.cordova -> Gives current version of cordova running on device.
//device.platrof -> Gives the name of platform.
//device.uuid -> Gives the UUID.
//device.version -> Gives the Android Version.
function onDeviceReady() {
var vInfo = 'Device Name: ' + device.name + '\n' +
'Device Cordova: ' + device.cordova + '\n' +
'Device Platform: ' + device.platform + '\n' +
'Device UUID: ' + device.uuid + '\n' +
'Device Version: ' + device.version;
alert(vInfo);
}
</script>
</head>
<body>
</body>
</html>
Author by
lola_the_coding_girl
Updated on June 15, 2022Comments
-
lola_the_coding_girl almost 2 years
I have a simple Phonegap Build application where I am trying to use the device plugin. I have installed the plugin via command line and have confirmed that it is installed.
I have the following js inside onDeviceReady:
alert(device.platform);
andalert(device.model);
I get white screen with no alerts.
Chrome dev tools remote inspect console says: Uncaught ReferenceError: platform is not defined
The plugin is not being recognized.
-
laughingpine over 8 yearsCan we get a snippet of the code? is device defined (
console.log(device)
)? -
AnR over 8 yearsDid you find a solution? I am also facing exactly the same problem
-
-
Mohammad Zakaria almost 7 years<script type="text/javascript" src="cordova.js"></script> . Thank you, after importing cordova.js the problem is solved