Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
nativescript-dna-deviceinfo
Advanced tools
Readme
NativeScript plugin to acquire device info.
The plugin offers cross-platform utility APIs to retrieve or query device-related information. The utility APIs are available for iOS and Android platforms.
Kindly visit the typescript demo or js demo repository for practical implementation guidance and hints.
The Changelogs section is located towards the end of the document.
I welcome an appreciation email with suggestions and feedback. It will encourage me to provide new APIs and support. My email-id is Deepak Arora. Enjoy and I will be looking forward to your valuable feedback.
From the command prompt, go to your app's root folder and execute:
tns plugin add nativescript-dna-deviceinfo
This command automatically installs the necessary files, as well as stores nativescript-dna-deviceinfo as a dependency in your project's package.json file.
Various device-related APIs are accessible from the DeviceInfo class. To import the class, use one of the following forms:
TypeScript:
import { DeviceInfo } from "nativescript-dna-deviceinfo";
JavaScript:
const nativescript_dna_deviceinfo = require("nativescript-dna-deviceinfo");
const DeviceInfo = nativescript_dna_deviceinfo.DeviceInfo;
Below is the list of APIs with their supported platforms.
Kindly visit typescript demo or js demo repository for practical implementation guidance and hints.
API | Return Type | iOS | Android |
---|---|---|---|
totalMemory | number | + | + |
freeMemory | number | + | + |
totalStorageSpace | number | + | + |
freeStorageSpace | number | + | + |
deviceId | string | + | + |
deviceName | string | + | + |
deviceLocale | string | + | + |
deviceCountry | string | + | + |
timezone | string | + | + |
userAgent | Promise | + | + |
appName | string | + | + |
appVersion | string | + | + |
bundleId | string | + | + |
bundleNumber | string | + | - |
systemManufacturer | string | + | + |
batteryLevel | number | + | + |
cellularServiceProviders | Carrier[] | + | + |
externalStoragePaths | string[] | - | + |
storageVolumes | StorageVolume[] | - | + |
wifiSSID | string | + | + |
displayMetrics | DisplayMetrics | + | + |
wifiIpv4Address | string | + | + |
cellularIpv4Address | string | + | + |
dumpIpAddresses | Address[] | + | + |
audioVolumeLevel | number | + | + |
setAudioVolumeLevel | void | + | + |
screenBrightnessLevel | number | + | + |
setScreenBrightnessLevel | void | + | + |
isBluetoothHeadsetConnected | boolean | + | + |
isMicAvailable | boolean | + | + |
isPortrait | boolean | + | + |
isTablet | boolean | + | + |
is24Hour | boolean | + | + |
isEmulator | boolean | + | + |
isBatteryCharging | boolean | + | + |
isLocationEnabled | Promise | + | + |
isBluetoothEnabled | Promise | + | + |
Each of the above APIs is described in detail along with their platform requirements where it makes sense.
Returns total memory(RAM) size of a device in bytes.
DeviceInfo.totalMemory();
Returns free memory(RAM) size of a device in bytes.
DeviceInfo.freeMemory();
Returns total storage(internal) space of a device in bytes.
DeviceInfo.totalStorageSpace();
Returns free storage(internal) space of a device in bytes.
DeviceInfo.freeStorageSpace();
Returns a device ID.
DeviceInfo.deviceId();
Returns a device name.
DeviceInfo.deviceName();
Returns the locale of a device.
DeviceInfo.deviceLocale();
Returns the device country.
DeviceInfo.deviceCountry();
Returns the time zone of a device.
DeviceInfo.timezone();
Returns Promise which resolves to 'user agent' if fetched successfully, otherwise 'error'.
DeviceInfo.userAgent();
Returns an app name.
DeviceInfo.appName();
Returns an app version.
DeviceInfo.appVersion();
Returns an app bundle id.
DeviceInfo.bundleId();
Returns an app bundle number.
DeviceInfo.bundleNumber();
Returns a device manufacturer.
DeviceInfo.systemManufacturer();
Returns the charge level of a device battery.
DeviceInfo.batteryLevel();
Returns a list of GSM network providers, Carrier, in use by device. In absence of adequate permission, returns empty Carrier list.
let carriers = DeviceInfo.cellularServiceProviders();
console.log(carriers);
Below is the Carrier interface:
interface Carrier {
carrierName: string;
displayName: string;
country: string;
mobileCountryCode: string;
isoCountryCode: string;
countryCode: string;
mobileNetworkCode: string;
generation: WCTGeneration; // Wireless Cellular Technology
networkType: RadioAccessTechnology;
}
Besides other helpful information returned from the API, it can be used to know whether the device has a fast internet connection or not.
Returns a list of paths for all mountable volumes (external storage cards, USB O-T-G). The empty list means that no mountable volumes found.
DeviceInfo.externalStoragePaths();
Returns a list of StorageVolume. An empty list means that no mountable volumes found.
let storageVolumes = DeviceInfo.storageVolumes();
console.log(storageVolumes);
Below is the StorageVolume interface:
interface StorageVolume {
path: string;
totalSize: number;
availableSize: number;
lowBytesLimit: number;
fullBytesLimit: number;
description: string;
isRemovableStorage: boolean;
isAllowMassStorage: boolean;
isEmulated: boolean;
isPrimary: boolean;
}
Returns service set identifier(SSID) of a wireless local area network (WLAN). In absence of right permissions, returns an empty string.
DeviceInfo.wifiSSID();
Notes for Android users:
Notes for iOS users:
<key>com.apple.developer.networking.wifi-info</key>
<true/>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/ PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.networking.wifi-info</key>
<true/>
</dict>
</plist>
Returns DisplayMetrics of a device.
DeviceInfo.displayMetrics();
Below is the DisplayMetrics interface:
interface DisplayMetrics {
scale: number;
pixelPerInch: number;
widthInPixels: number;
heightInPixels: number;
diagonalInInches: number;
}
Returns WiFi IPv4 address.
DeviceInfo.wifiIpv4Address();
Returns cellular IPv4 address.
DeviceInfo.cellularIpv4Address();
Returns Address[], which is a collection of IPv4 and IPv6 addresses that a device is equipped with.
DeviceInfo.dumpIpAddresses();
Returns the audio volume level as a scalar value from 0 to 100.
DeviceInfo.audioVolumeLevel();
Sets the audio volume level. The level should be a scalar value from 0 and 100.
DeviceInfo.setAudioVolumeLevel(50);
Returns the screen brightness level as a scalar value from 0 to 10.
DeviceInfo.screenBrightnessLevel();
Sets the screen brightness level. The level should be a scalar value from 0 and 10.
DeviceInfo.setScreenBrightnessLevel(0.8);
Returns 'true' if a bluetooth headset is connected with the device, otherwise 'false'.
DeviceInfo.isBluetoothHeadsetConnected();
Returns 'true' if a mic, whether built-in or external, is available, otherwise 'false'.
DeviceInfo.isMicAvailable();
Returns 'true' if a device is in portrait mode, otherwise 'false'.
DeviceInfo.isPortrait();
Returns 'true' if a device is a tablet, otherwise 'false'.
DeviceInfo.isTablet();
Returns 'true' if a device configured to a 24-hour clock, otherwise 'false'.
DeviceInfo.is24Hour();
Returns 'true' if an app is running on an emulator, otherwise 'false'.
DeviceInfo.isEmulator();
Returns 'true' if a device is plugged in and charging, otherwise 'false'.
DeviceInfo.isBatteryCharging();
Depending on the state of Location Service and the app permission, returned Promise may resolve to 'true' or 'false'. In the absence of appropriate permission, rejected Promise is returned.
DeviceInfo.isLocationEnabled().then(value => console.log(value))
.catch(error => console.log(error));
async LocationServiceStatus() {
const status = await DeviceInfo.isLocationEnabled().catch(error => console.log(error));
console.log(status);
}
Depending on the state of Bluetooth and the app permission, returned Promise may resolve to 'true' or 'false'. In the absence of appropriate permission, rejected Promise is returned.
DeviceInfo.isBluetoothEnabled().then(value => console.log(value))
.catch(error => console.log(error));
async PrintBluetoothStatus() {
const status = await DeviceInfo.isBluetoothEnabled().catch(error => console.log(error));
console.log(status);
}
async printDeviceInfo() {
console.log("Free memory: ", getSize(DeviceInfo.freeMemory()));
console.log("Total memory: ", getSize(DeviceInfo.totalMemory()));
console.log("Total storage space: ", getSize(DeviceInfo.totalStorageSpace()));
console.log("Free storage space: ", getSize(DeviceInfo.freeStorageSpace()));
console.log("Device id: ", DeviceInfo.deviceId());
console.log("Device name: ", DeviceInfo.deviceName());
console.log("Device locale: ", DeviceInfo.deviceLocale());
console.log("Device country: ", DeviceInfo.deviceCountry());
console.log("Device timezone: ", DeviceInfo.timezone());
console.log("Device user agent: ", await DeviceInfo.userAgent().catch(error => console.log(error)));
console.log("App name: ", DeviceInfo.appName());
console.log("App version: ", DeviceInfo.appVersion());
console.log("App bundle id: ", DeviceInfo.bundleId());
console.log("App bundle number: ", DeviceInfo.bundleNumber());
console.log("System manufacturer: ", DeviceInfo.systemManufacturer());
console.log("Battery level: ", Math.round(DeviceInfo.batteryLevel()));
console.log("Storage paths: ", DeviceInfo.externalStoragePaths());
console.log("Storage volume info: ", DeviceInfo.storageVolumes());
console.log("WiFi SSID: ", DeviceInfo.wifiSSID());
console.log("Display metrics: ", DeviceInfo.displayMetrics());
console.log("Is portrait orientation: ", DeviceInfo.isPortrait());
console.log("Is tablet: ", DeviceInfo.isTablet());
console.log("Is 24 hour: ", DeviceInfo.is24Hour());
console.log("Is emulator: ", DeviceInfo.isEmulator());
console.log("Is battery charing: ", DeviceInfo.isBatteryCharging());
console.log("Is Location service enabled: ", await DeviceInfo.isLocationEnabled().catch(error => console.log(error)));
}
formatBytes(bytes, decimals) {
if (bytes === 0) return '0 GB'
if (isNaN(parseInt(bytes))) return bytes
if (typeof bytes === 'string') bytes = parseInt(bytes)
if (bytes === 0) return '0';
const k = 1000;
const dm = decimals + 1 || 3;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
}
getSize(bytes: number) {
return formatBytes(bytes, 2);
}
iPhone1,1
, Watch1,1
, etc.) and their matching product names.MIT license (see LICENSE file)
FAQs
NativeScript plugin to acquire device information.
The npm package nativescript-dna-deviceinfo receives a total of 567 weekly downloads. As such, nativescript-dna-deviceinfo popularity was classified as not popular.
We found that nativescript-dna-deviceinfo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.