Search code examples
javascriptjquerycordovaphonegap-plugins

cordova get device UUID globally


i am using cordova plugin in one of my app,i am need a device UUId,device unique id and i want to use it globally,i am able to get it inside the onDeviceReady() function,but i am unable to use it globally need help.

var deviceName
var deviceUID
var deviceOs
var deviceOsVersion
document.addEventListener("deviceready", onDeviceReady, false)
function onDeviceReady() {
deviceName = device.name;
deviceUID = device.uuid;
deviceOs = device.platform;
deviceOsVersion = device.version;
//Use device information as required
// userDetails(deviceUID);
console.log("devicename : " + deviceName + " deviceId: " + deviceUID + " deviceOs: " + deviceOs + " deviceosversion : " + deviceOsVersion);

 }
   //Use device information as required
   // userDetails(deviceUID);
  console.log("devicename : " + deviceName + " deviceId: " + deviceUID + "     deviceOs: " + deviceOs + " deviceosversion : " + deviceOsVersion);

Solution

  • To SET item

    window.localStorage.setItem("uuid", deviceUID);
    

    To GET item value

    window.localStorage.getItem("uuid");
    

    To REMOVE value

    localStorage.removeItem("uuid");
    

    or even

    localStorage.clear();
    

    Remember you need <script src="cordova.js"></script> in you index.html