【问题标题】:Apache Cordova device.uuidApache Cordova device.uuid
【发布时间】: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);
        }

    }
};

【问题讨论】:

    标签: android cordova


    【解决方案1】:

    您需要将设备插件添加到您的应用中 跑吧

    cordova plugin add --save cordova-plugin-device
    

    【讨论】:

      猜你喜欢
      • 2016-08-23
      • 2020-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多