2
votes

I Have a problem with Cordova/Phonetgap Device API, the objetc device isn't found. I make callback to device.model or any fecture of device and return:

ReferenceError: Can't find variable: device at file:///android_asset/www/index.html:16

I'm following this steps: http://cordova.apache.org/docs/en/3.3.0/cordova_device_device.md.html#Device firts create the cordova android project and later I Install plugin device through: "cordova plugin add org.apache.cordova.device" I'm testing with this index.html:

<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>

<script type="text/javascript" charset="utf-8">

// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);

// device APIs are available
//
function onDeviceReady() {
    var string = device.platform;
    var element = document.getElementById('deviceProperties');
    element.innerHTML =  string;
}

</script>
</head>
<body>
     <p id="deviceProperties">Loading device properties...</p>
</body>
</html>

I have in app/res/xml/config.xml this lines:

<feature name="Device">
    <param name="android-package" value="org.apache.cordova.device.Device" />
</feature>

Here There is a screenshot for more details: https://dl.dropboxusercontent.com/u/6404856/Helpme.JPG

2

2 Answers

1
votes

as I see you're using eclipse, did you run cordova prepare android or cordova build android after you installed the plugin? (be aware that it will overwrite your assets/www folder with the content of the www folder at the root of the project)

0
votes

Your code looks good to me. Try running cordova plugin ls and make sure the device plugin shows up. Also try uninstalling then reinstalling it. If that doesn't work then try deleting the your_project/plugins/android.json file, reinstall plugin, then build the android platform. Sometimes the android.json doesn't get updated correctly and this messes it all up.