2

I need to find the device ID on which my app is running. I am using angular js and ionic. Is there any way to obtain the device ID?

pritam kale
  • 75
  • 2
  • 12
  • Possible duplicate of [How to get the device UUID in ionic framework](http://stackoverflow.com/questions/27466813/how-to-get-the-device-uuid-in-ionic-framework) – SiddAjmera May 25 '16 at 04:41
  • What do you need the device ID for? I ask because searching for Cordova device ID comes back with some optional plugins but depends on what you're trying to use the "ID" for or which particular ID you need depending on your needs – shaunhusain May 25 '16 at 04:43
  • use this plugin `cordova plugin add cordova-plugin-device` to get the device ID and for reference to use different methods follow this [link](http://ngcordova.com/docs/plugins/device/) – Anil kumar May 25 '16 at 04:48
  • @pritam kale check this answer i have already answered this question http://stackoverflow.com/questions/36717556/retrieve-the-device-token-from-device-using-ionic-framework/36717874#36717874 – Mohan Gopi May 25 '16 at 05:08
  • Thanks guys....I have used window.device plugin to get the uuid... – pritam kale May 25 '16 at 08:48

1 Answers1

1

Option 1: Use AngularJS run

// Calling the rootScope to handle the  ondevice ready
angular.module('myApp').run(['$rootScope', function($rootScope) {
  document.addEventListener('deviceready', function() {
      $rootScope.$apply(function() {
          $rootScope.myVariable = "variable value";
          try {
            $rootScope.uuid = device.uuid; //always use device object after deviceready.**
            alert($rootScope.uuid);
            //onapploginx(uuid);
          } catch (e) {
            alert(e);
          }
          // Register the event listener
          document.addEventListener("backbutton", onBackKeyDown, false);
      });
  });
}]);

Option 2: Use JS only

define the onLoad in the body

<body id="main_body" ng-app='myApp' ng-controller='DemoController' onload="onLoad()"> 

call addEventListener for device ready and then call the function of onDeviceReady

function onLoad() {
  console.log("i am onload");
  document.addEventListener("deviceready", onDeviceReady, false);
}

// device APIs are available
//
function onDeviceReady() {
  try {
    var uuid = device.uuid; //always use device object after deviceready.**
    alert("uuidx:",uuid);
  } catch (e) {
    alert(e);
  }
}
Ayman Salama
  • 419
  • 3
  • 10