1

开门见山。

我正在尝试使用 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);
        }

    }
};
4

1 回答 1

0

您需要将设备插件添加到您的应用程序中才能运行

cordova plugin add --save cordova-plugin-device
于 2017-02-14T10:33:53.137 回答