The cordova device plugin , can be used to get the hardware and software information , for a mobile device .
Table of Contents
Information that can be gotten using the device plugin
The plugin adds a global device object , which can be accessed when the deviceready event is fired . The properties attached to the device object , are :
device.cordova : The version of cordova running on the phone.
device.version : The device manufacturer .
device.model : The name of the device or of the model .
device.platform : The name of the operating system .
device.version : The version of the operating system .
device.isVirtual : True of false , if device is running or not in an emulator .
device.uuid : The device universally unique identifier . For android cordova returns the ANDROID_ID . For devices having an android version less than 8 , this is a 64 bit random number , generated on the device first boot . For android devices having android version equal to 8 or higher , this is a 64 bit number unique to each combination of signing key , user , and device . The ANDROID_ID may be changed when a device is reset , and for android version 8 or higher, it might also be changed when an apk signing key changes .
For iOS , this is a vendor generated unique identifier , for all the vendor applications , when all the vendor applications are deleted , the vendor unique identifier is regenerated .
device.serial The device hardware serial number , this is only available for android .
A demo application
Create an application using these commands :
$ cordova create demo-device com.twiserandom.mobileapps.demoDevice "Demo Device Plugin" $ cd demo-device $ cordova platform add ios $ cordova platform add android $ cordova plugin add cordova-plugin-device
Edit www/index.html to look like this :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
<meta name="color-scheme" content="light dark">
<title>Demo Device Plugin</title>
</head>
<body>
<div class="app">
<div id="console">
<h1>Device plugin</h1>
</div>
</div>
<script src="cordova.js"></script>
<script src="js/index.js"></script>
</body>
</html>
Edit www/js/index.js to look like this :
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
let console = document.getElementById("console");
function logToConsole(key , value){
console.innerHTML += `<p>${key} : ${value}</p>`;
console.innerHTML += "<hr/>"; }
logToConsole("Cordova Version" , device.cordova );
logToConsole("Device manufacturer" , device.manufacturer );
logToConsole("Device model" , device.model );
logToConsole("Device platform" , device.platform );
logToConsole("Device version" , device.version );
logToConsole("Device isVirtual" , device.isVirtual );
logToConsole("Device uuid" , device.uuid );
logToConsole("Device serial" , device.serial ); }
Run the application on an emulator like so :
$ cordova emulate android # For android $ cordova emulate ios # For iOS
Can such plugins be used to model user information ?
The device model and manufacturer can be used to know what device the user is buying . Research is , and can be made , on who buy which device , the category of peoples that this person belongs to , how much money this person is making , his age , and other demographics , a reverse analysis .
The device operating system , and its version , can be used to assess if the device can be hacked , or if there are security vulnerabilities found on this device . It can also be used to get demographic information , such as , what kind of people buy android or iOS , or use chrome or firefox … a user modeling , to push services maybe .
The uuid and device serial are of interest to track the liking of the user , what he is doing , and to get information from more than one source .



