Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nativescript-dna-deviceinfo

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nativescript-dna-deviceinfo

NativeScript plugin to acquire device information.

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

NativeScript DNA Device Info

nativescript-dna-deviceinfo

NativeScript plugin to acquire device info.

Features

  • Cross-platform APIs for Android and iOS.
  • Offers APIs to obtain device related info.

Changelogs:

  • 1.0.0: First release.
  • 1.0.1: Minor document correction.
  • 1.1.0: New APIs related to battery charging status and its charge level.
  • 1.1.1: Updated document.
  • 1.2.0: Added an API to retrieve Network Providers, Carriers, related information.

Installation

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.

Import / require

Various device related utility 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;

APIs

- totalMemory

Returns the total memory(RAM) size of a device in bytes.

DeviceInfo.totalMemory();

- freeMemory

Returns the free memory(RAM) size of a device in bytes.

DeviceInfo.freeMemory();

- totalStorageSpace

Returns the total storage(internal) space of a device in bytes.

DeviceInfo.totalStorageSpace();

- freeStorageSpace

Returns the free storage(internal) space of a device in bytes.

DeviceInfo.freeStorageSpace();

- deviceId

Returns a device ID.

DeviceInfo.deviceId();

- deviceName

Returns a device name.

DeviceInfo.deviceName();

- deviceLocale

Returns the locale of a device.

DeviceInfo.deviceLocale();

- deviceCountry

Returns the device country.

DeviceInfo.deviceCountry();

- timezone

Returns the time zone of a device.

DeviceInfo.timezone();

- userAgent

Returns the user agent string of a device.

DeviceInfo.userAgent();

- appName

Returns the app name.

DeviceInfo.appName();

- appVersion

Returns an app version.

DeviceInfo.appVersion();

- bundleId

Returns an app bundle id.

DeviceInfo.bundleId();

- bundleNumber

Returns an app bundle number.

DeviceInfo.bundleNumber();

- systemManufacturer

Returns a device manufacturer.

DeviceInfo.systemManufacturer();

- batteryLevel

Returns the charge level of a device battery.

DeviceInfo.batteryLevel();

- isTablet

Returns 'true' if a device is a tablet, otherwise 'false'.

DeviceInfo.isTablet();

- is24Hour

Returns 'true' if a device configured to a 24-hour clock, otherwise 'false'.

DeviceInfo.is24Hour();

- isEmulator

Returns 'true' if an app is running on an emulator, otherwise 'false'.

DeviceInfo.isEmulator();

- isBatteryCharging

Returns 'true' if a device is plugged in and charging, otherwise 'false'.

DeviceInfo.isBatteryCharging();

- cellularServiceProvider

Returns a list of GSM network providers, carriers, of a device is equipped with.

DeviceInfo.cellularServiceProvider();

Besides other helpful information returned from the API, it can be used to know whether the device has a fast internet connection or not.

  • Note for Android users:
    • If the targetSdkVersion is 17, a device with dual sim, the API returns an "active" carrier. Permission ACCESS_COARSE_LOCATION is needed.
    • If the targetSdkVersion is >= 22, a device with dual sim, the API returns both the carriers. Permission READ_PHONE_STATE is needed. To know more about the request permissions process, please visit the link Request App Permissions.

APIs in Action

  printDeviceInfo() { 
    console.log("Free memory: ", formatBytes(DeviceInfo.freeMemory()));
    console.log("Total memory: ", formatBytes(DeviceInfo.totalMemory()));
    console.log("Total storage space: ", formatBytes(DeviceInfo.totalStorageSpace()));
    console.log("Free storage space: ",formatBytes(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: ", DeviceInfo.userAgent());
    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("Is tablet: ", DeviceInfo.isTablet());
    console.log("Is 24 hour: ", DeviceInfo.is24Hour());
    console.log("Is emulator: ", DeviceInfo.isEmulator());
    console.log("Is battery charing: ",  DeviceInfo.isBatteryCharging());
  }

  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]}`;
  }

License

MIT license (see LICENSE file)

Keywords

FAQs

Package last updated on 15 Jun 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc