Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Cordova device


May 21, 2021 Cordova


Table of contents


This plug-in is used to obtain information about the user's device.

Step 1 - Install the device plug-in

To install this plug-in, we need to run the following snippppppy code in the command prompt.

C:\Users\username\Desktop\CordovaProject>cordova plugin add cordova-plugin-device

Step 2 - Add a button

We will use this plug-in just as we do with other Cordova plug-ins. /b10> Let's add .html the index file. /b11> This button will be used to obtain information for the device.

<button id = "cordovaDevice">CORDOVA DEVICE</button>

Step 3 - Add an event listener

The Cordova plug-in is available after the deviceready event, so we'll place the event listener in the onDeviceReady function in index .js.

document.getElementById("cordovaDevice").addEventListener("click", cordovaDevice);	

Step 4 - Create a function

The Cordova plug-in is available after the deviceready event, so we'll place the event listener in the onDeviceReady function in index .js.

function cordovaDevice() {
   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 the CORDOVA DEVICE button, the alert will display the Cordova version, device model, platform, UUID, and device version.

Cordova device