Saturday 7 September 2013

Cordova 3.0.0 Device Api is not working

Cordova 3.0.0 Device Api is not working

I write small app to get device name View in html page but my problem is
not getting device information after on my test device this is my
javascript
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
this.testZone = {};
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
document.addEventListener('pause', this.onPause, false);
document.addEventListener('resume', this.onResume, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
console.log("Ready");
//app.receivedEvent('deviceready');
app.testZone = document.getElementById("test-zone");
app.testZone.innerHTML = "Ready";
app.getDeviceInfo();
},
// Update DOM on a Received Event
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);
},
onPause: function(){
app.testZone.innerHTML += "<br/> Pause";
},
onResume: function(){
app.testZone.innerHTML += "<br/> Resume";
},
getDeviceInfo: function(){
app.testZone.innerHTML += 'Device Name: ' + device.name +
'<br />' +
'Device Cordova: ' + device.cordova + '<br />' +
'Device Platform: ' + device.platform + '<br />' +
'Device UUID: ' + device.uuid + '<br />' +
'Device Version: ' + device.version + '<br />';
}
};

No comments:

Post a Comment