or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

application-information.mdbattery-power.mddevice-identification.mdhardware-features.mdindex.mdmemory-storage.mdnetwork-connectivity.mdreact-hooks.mdsystem-information.md
tile.json

tessl/npm-react-native-device-info

Get device information using react-native

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/react-native-device-info@14.0.x

To install, run

npx @tessl/cli install tessl/npm-react-native-device-info@14.0.0

index.mddocs/

React Native Device Info

React Native Device Info is a comprehensive cross-platform library that provides access to device and system information across iOS, Android, Windows, and web platforms. It offers a rich API for retrieving device details including hardware specifications, system information, unique identifiers, battery status, network information, and device capabilities with both synchronous and asynchronous data retrieval patterns.

Package Information

  • Package Name: react-native-device-info
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install react-native-device-info

Core Imports

import DeviceInfo from 'react-native-device-info';

// Or ES6+ destructured imports
import { 
  getUniqueId, 
  getManufacturer, 
  getBatteryLevel,
  isTablet,
  useBatteryLevel 
} from 'react-native-device-info';

For CommonJS:

const DeviceInfo = require('react-native-device-info');

// Or destructured
const { getUniqueId, getManufacturer } = require('react-native-device-info');

Basic Usage

import { 
  getUniqueId, 
  getManufacturer, 
  getBatteryLevel,
  isTablet,
  getSystemVersion 
} from 'react-native-device-info';

// Basic device identification
const deviceId = await getUniqueId();
const manufacturer = await getManufacturer();
const isTabletDevice = isTablet();

// System information
const osVersion = getSystemVersion();

// Battery status
const batteryLevel = await getBatteryLevel();

console.log(`Device: ${manufacturer} (${deviceId})`);
console.log(`OS Version: ${osVersion}`);
console.log(`Device Type: ${isTabletDevice ? 'Tablet' : 'Phone'}`);
console.log(`Battery: ${Math.round(batteryLevel * 100)}%`);

Architecture

React Native Device Info is built around several key architectural components:

  • Platform Detection: Automatic platform-specific implementation routing for iOS, Android, Windows, and web
  • Sync/Async Patterns: Dual API approach with both synchronous and asynchronous versions of most methods
  • Memoization: Built-in caching system for frequently accessed device properties to improve performance
  • React Hooks Integration: Custom hooks for real-time monitoring of dynamic device states
  • Graceful Fallbacks: Default values ("unknown", -1, false, []) for unsupported platforms or unavailable features
  • Type Safety: Comprehensive TypeScript definitions with platform-specific type narrowing

Capabilities

Device Identification

Core device identification functionality for retrieving unique identifiers, device details, and hardware information. Essential for analytics, device tracking, and platform-specific behavior.

function getUniqueId(): Promise<string>;
function getUniqueIdSync(): string;
function getDeviceId(): string;
function getModel(): string;
function getBrand(): string;
function getManufacturer(): Promise<string>;
function getManufacturerSync(): string;

Device Identification

System Information

System and operating system information including OS version, build details, and platform-specific system properties. Critical for compatibility checks and platform-specific feature detection.

function getSystemName(): string;
function getSystemVersion(): string;
function getBuildId(): Promise<string>;
function getBuildIdSync(): string;
function getApiLevel(): Promise<number>;  // Android only
function getApiLevelSync(): number;       // Android only
function supportedAbis(): Promise<string[]>;
function supportedAbisSync(): string[];
function hasSystemFeature(feature: string): Promise<boolean>;  // Android only
function hasSystemFeatureSync(feature: string): boolean;       // Android only
function getStartupTime(): Promise<number>;
function getStartupTimeSync(): number;

System Information

Application Information

Application metadata including version information, installation details, and app-specific identifiers. Useful for app analytics, version checking, and installation tracking.

function getApplicationName(): string;
function getBundleId(): string;
function getVersion(): string;
function getBuildNumber(): string;
function getReadableVersion(): string;
function getFirstInstallTime(): Promise<number>;
function getFirstInstallTimeSync(): number;

Application Information

Memory and Storage

Memory usage and storage capacity information for performance monitoring and storage management. Essential for optimizing app performance and managing device resources.

function getUsedMemory(): Promise<number>;
function getUsedMemorySync(): number;
function getTotalMemory(): Promise<number>;
function getTotalMemorySync(): number;
function getFreeDiskStorage(): Promise<number>;
function getFreeDiskStorageSync(): number;
function getTotalDiskCapacity(): Promise<number>;
function getTotalDiskCapacitySync(): number;

Memory and Storage

Battery and Power

Battery status and power management information for power-aware applications and battery optimization. Critical for apps that need to adapt behavior based on battery state.

function getBatteryLevel(): Promise<number>;
function getBatteryLevelSync(): number;
function getPowerState(): Promise<Partial<PowerState>>;
function getPowerStateSync(): Partial<PowerState>;
function isBatteryCharging(): Promise<boolean>;
function isBatteryChargingSync(): boolean;

interface PowerState {
  batteryLevel: number;
  batteryState: BatteryState;
  lowPowerMode: boolean;
  [key: string]: any;
}

type BatteryState = 'unknown' | 'unplugged' | 'charging' | 'full';

Battery and Power

Network and Connectivity

Network and connectivity information including IP addresses, carrier information, and connection status. Important for network-aware applications and connectivity debugging.

function getIpAddress(): Promise<string>;
function getIpAddressSync(): string;
function getCarrier(): Promise<string>;
function getCarrierSync(): string;
function getMacAddress(): Promise<string>;
function getMacAddressSync(): string;
function isAirplaneMode(): Promise<boolean>;
function isAirplaneModeSync(): boolean;

Network and Connectivity

Hardware Features

Hardware feature detection and capability checking for cameras, audio devices, input peripherals, and platform-specific hardware. Essential for feature-dependent applications.

function isCameraPresent(): Promise<boolean>;
function isCameraPresentSync(): boolean;
function isHeadphonesConnected(): Promise<boolean>;
function isHeadphonesConnectedSync(): boolean;
function hasNotch(): boolean;
function hasDynamicIsland(): boolean;
function isTablet(): boolean;
function isEmulator(): Promise<boolean>;
function isEmulatorSync(): boolean;

Hardware Features

React Hooks

Real-time monitoring hooks for dynamic device states and event-driven updates. Perfect for React components that need to respond to device state changes automatically.

function useBatteryLevel(): number | null;
function usePowerState(): Partial<PowerState>;
function useDeviceName(): AsyncHookResult<string>;
function useIsHeadphonesConnected(): AsyncHookResult<boolean>;
function useBrightness(): number | null;

interface AsyncHookResult<T> {
  loading: boolean;
  result: T;
}

React Hooks

Types

type DeviceType = 'Handset' | 'Tablet' | 'Tv' | 'Desktop' | 'GamingConsole' | 'unknown';

type BatteryState = 'unknown' | 'unplugged' | 'charging' | 'full';

type AvailableCapacityType = 'total' | 'important' | 'opportunistic';

interface PowerState {
  batteryLevel: number;
  batteryState: BatteryState;
  lowPowerMode: boolean;
  [key: string]: any;
}

interface LocationProviderInfo {
  [key: string]: boolean;
}

interface AsyncHookResult<T> {
  loading: boolean;
  result: T;
}