Skip to main content

DeviceInfo

import { DeviceInfo } from 'nitro-device-info'

DeviceInfo is a Nitro hybrid object with static methods only; there is nothing to construct. It is implemented by HybridDeviceInfo in Swift on iOS and in Kotlin on Android. NitroUI runs JavaScript on the main thread, so every method is entered there.

MethodReturns
getDeviceDetails()DeviceDetails, cached
getPowerState()PowerState
addOnPowerStateChangedListener(listener)ListenerSubscription
getUsedMemory()number, bytes
getFontScale()number
getVendorId()string | undefined
isHeadphonesConnected()boolean
isPasscodeSet()boolean
isLocationEnabled()Promise<boolean>
getUserAgent()Promise<string>
getSystemFeatures()string[]
hasSystemFeature(feature)boolean

getDeviceDetails​

static getDeviceDetails(): DeviceDetails

Returns the device and app values that stay the same while the app runs. They are read on the first call and cached, so every call returns the same values. See Device details for how the derived fields are computed.

getPowerState​

static getPowerState(): PowerState

Returns the battery level, whether the battery charges, and whether power saving is on. See Power state.

addOnPowerStateChangedListener​

static addOnPowerStateChangedListener(
listener: (state: PowerState) => void,
): ListenerSubscription

Observes changes to the power state. The listener runs only when a PowerState field changes, not when it is added. Call remove() on the returned subscription when observation is no longer needed; the native observer stops when the last listener is removed.

getUsedMemory​

static getUsedMemory(): number

Returns the physical memory in bytes the app uses: the memory footprint on iOS, the proportional set size on Android.

getFontScale​

static getFontScale(): number

Returns the user's text size relative to the default, for example 1.3 for larger text.

getVendorId​

static getVendorId(): string | undefined

Returns an identifier that stays the same for the app on this device: identifierForVendor on iOS, shared by apps of the same vendor, and ANDROID_ID on Android, scoped to the app's signing key. Returns undefined on iOS before the user first unlocks the device after a restart.

isHeadphonesConnected​

static isHeadphonesConnected(): boolean

Returns whether wired or Bluetooth headphones are connected as an audio output.

isPasscodeSet​

static isPasscodeSet(): boolean

Returns whether the device has a passcode, PIN, pattern or password set.

isLocationEnabled​

static isLocationEnabled(): Promise<boolean>

Resolves whether location services are on for the device. It does not tell whether the app may use them. On iOS the check runs off the main thread, because Apple warns that it blocks.

getUserAgent​

static getUserAgent(): Promise<string>

Resolves the user agent of the platform's web view. The first call loads the web view: a short-lived WKWebView on iOS, whose result is cached, and the WebView provider off the main thread on Android. The promise rejects if the web view returns no user agent.

getSystemFeatures​

static getSystemFeatures(): string[]

Returns the system features the device declares, such as android.hardware.nfc (PackageManager.systemAvailableFeatures). Empty on iOS.

hasSystemFeature​

static hasSystemFeature(feature: string): boolean

Returns whether the device declares the given system feature. Always false on iOS.

const hasNfc = DeviceInfo.hasSystemFeature('android.hardware.nfc')