English 中文(简体)
Cordova - Device
  • 时间:2024-10-18

Cordova - Device


Previous Page Next Page  

This plugin is used for getting information about the user’s device.

Step 1 - Instalpng Device Plugin

To install this plugin, we need to run the following snippet in the command prompt.

C:UsersusernameDesktopCordovaProject>cordova plugin add cordova-plugin-device

Step 2 - Adding Button

We will be using this plugin the same way we used the other Cordova plugins. Let us add a button in the index.html file. This button will be used for getting information about the device.

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

Step 3 - Adding Event Listener

Cordova plugins are available after the deviceready event so we will place the event pstener inside the onDeviceReady function in index.js.

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

Step 4 - Creating Function

The following function will show how to use all possibipties the plugin provides. We will place it in index.js.

function cordovaDevice() {
   alert("Cordova version: " + device.cordova + "
" +
      "Device model: " + device.model + "
" +
      "Device platform: " + device.platform + "
" +
      "Device UUID: " + device.uuid + "
" +
      "Device version: " + device.version);
}

When we cpck the CORDOVA DEVICE button, the alert will display the Cordova version, device model, platform, UUID and device version.

Cordova Device Alert Advertisements