In this tutorial, you will learn, how to retrieve device information such as device model, device operating system (OS), etc. Using cordovaDevice plugin.

Start a blank ionic project using.


ionic start deviceinfo blank

Go to deviceinfo folder.


cd deviceinfo

Now add cordovaDevice plugin using.


cordova plugin add cordova-plugin-device

Download the ngCordova library.


https://github.com/driftyco/ng-cordova/archive/master.zip

Extract it and you can find ng-cordova.min.js file in the dist folder.

Copy that file to your js folder and include the ngCordova js file in index.html before cordova.js.


<script type="text/javascript" src="js/ng-cordova.min.js" ></script>

Then go to js folder and open app.js file Replace.


angular.module('starter', ['ionic'])

with


angular.module('starter', ['ionic','ngCordova'])

Add ngCordova in Angular module as mentioned above. AngularJS starts with a controller.

Therefore, add a controller in HTML and set up the code for the controller in app.js. In HTML, add controller


<body ng-app="starter" ng-controller="devctrl">

In app.js , at the end of the code, add


.controller('devctrl',function($scope,$ionicPlatform,$cordovaDevice){

 $ionicPlatform.ready(function() {


   var element = document.getElementById('demo');

    element.innerHTML = 'Device Model: '    + $cordovaDevice.getModel()    + '<br />' +

    'Cordova Version: ' + $cordovaDevice.getCordova() + '<br />' +

    'Device Platform: ' + $cordovaDevice.getPlatform() + '<br />' +

    'Device UUID: '     + $cordovaDevice.getUUID()     + '<br />' +

    'OS Version: ' + $cordovaDevice.getVersion() + '<br />';

});
})

Give the same controller name, which is mentioned in your HTML file.

Then include cordovaDevice service. The above code gets the device information and displays them in your app.

Add Android platform to your app.


ionic platform add android

Generate apk file using.


ionic build android

That's all. You're done.

Install the apk on your phone and check your device information.

The apk file path is shown in git or command prompt.

 

Tested Device

Samsung J7 Android Lolipop.

Source

APK