When you are building an app that demands to check the information about the device, then you can integrate this plugin and make your work done

This plugin can be used for getting information about the users device.

Step 1 - Installing Device Plugin

To install this plugin, open command prompt window and run the following piece of code.

C:\Users\username\Desktop\CordovaProject>cordova plugin add cordova-plugin-device
 Step 2 - Add Button

You can use this plugin in the same way you used the other Cordova plugins. Add button in index.html file. This button will be used for fetching info about the user’s device.

<button id = "DeviceInfo">GET INFO</button>
 Step 3 - Adding Event Listener

Cordova plugins are available after the deviceready event so event listener will be placed inside onDeviceReady function in index.js file.

document.getElementById("DeviceInfo").addEventListener("click", DeviceInfo);   
 Step 4 - Creating Function

The function below should be placed in index.js file. It will show you how to use all capabilities the plugin provides.

function DeviceInfo() {

   alert("Cordova version: " + device.cordova + "\n" +
      "Device model: " + device.model + "\n" +
      "Device platform: " + device.platform + "\n" +
      "Device UUID: " + device.uuid + "\n" +
      "Device version: " + device.version);
}
 

When we click GET INFO button, the alert will display us Cordova version, device model, platform, UUID and device version of the user’s device.

Cordova – Displaying Device Info

  Modified On Mar-19-2018 01:38:22 AM

Leave Comment