1

要点にまっすぐ。

Apache Cordova 3.1.0 を使用して Android フォンの device.uuid を取得しようとしています。

cordova を使用してサンプル add を作成しました。

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