【发布时间】:2013-11-15 08:01:16
【问题描述】:
直截了当。
我正在尝试使用 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);
}
}
};
【问题讨论】: