开门见山。
我正在尝试使用 Apache Cordova 3.1.0 为我的 android 手机获取 device.uuid。
我使用cordova创建了一个示例添加:
cordova-android/bin/create mobile-client
示例应用程序运行良好。然后我添加了一些代码来获取设备 uuid。
但我收到以下错误:
TypeError: Cannot read property 'uuid' from undefined
这是我的javascript:
var app = {
initialize: function () {
this.bindEvents();
},
bindEvents: function () {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function () {
app.receivedEvent('deviceready');
},
receivedEvent: function (id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
try {
alert(device.uuid);
} catch (e) {
alert(e);
}
}
};