Command palette

@yasinsensoy/native

React Native · APIs and utilities

Device

Device and app info.

5 exports

Import

import { Device, useBattery } from "@yasinsensoy/native";

Device

module

Device and app info. Fields are read from the native module on first access.

NameTypeDescription
brandstringBrand (Apple, samsung, google…).
manufacturerstringManufacturer.
modelstringModel name (Android: Pixel 8; iOS: iPhone/iPad).
modelIdstringHardware id (iOS: iPhone16,1; Android: the device code name).
osNameDeviceConstants["osName"]iOS, iPadOS or Android.
osVersionstringOperating system version (18.2, 15).
apiLevelnumber | nullAndroid API level; null on iOS.
isEmulatorbooleanWhether it is a simulator/emulator.
deviceTypeDeviceTypeDevice type.
totalMemorynumberTotal memory (bytes).
deviceNamestringDevice name set by the user. iOS 16+ returns the generic name (iPhone) without a special entitlement.
applicationIdstringBundle id (com.company.app).
appNamestringDisplay name of the app.
appVersionstringVersion (1.2.0).
buildNumberstringBuild number (42).
installTimenumber | nullFirst install time (ms, epoch); null if unknown.
getUniqueId() => Promise<string>Id specific to the device and the app (iOS identifierForVendor, Android ANDROID_ID). May change when the app is reinstalled (iOS) or the device is reset; it is not an advertising id.
getBattery() => Promise<BatteryState>Battery state.
getStorage() => Promise<StorageInfo>Storage space.
getUptime() => Promise<number>Time the device has been up (ms).
addBatteryListener(listener: (state: BatteryState) => void) => () => voidCalled when the battery changes. Returns a function that ends the subscription.

useBattery

function

Watches the battery state (null until the first value arrives).

useBattery(): BatteryState | null

Device type. desktop: an iPhone/iPad app on a Mac, or ChromeOS.

type DeviceType = "phone" | "tablet" | "desktop" | "tv" | "unknown"

BatteryState

interface

Battery state.

NameTypeDescription
levelnumber | nullCharge level (0–1); null if unknown (iOS simulator).
state"charging" | "full" | "unplugged" | "unknown"charging, full, unplugged or unknown.
lowPowerModebooleanWhether low power / battery saver mode is on.

StorageInfo

interface

Storage (bytes).

NameTypeDescription
freenumberAvailable space.
totalnumberTotal space.