Device
Device
device.Device
Singleton for device state, identifiers, display metrics, brightness, volume, vibration, and related helpers. Obtain it with:
const { device } = require("device");Inheritance
EventEmitter↳
Device
Table of contents
Accessors
- androidId
- battery
- batteryPluggedTypes
- bootloader
- brightness
- brightnessMode
- buildId
- cpuApis
- display
- displayMetrics
- externalStorageDirectory
- fingerprint
- hardware
- imei
- macAddress
- memoryInfo
- product
- screenHeight
- screenWidth
- serial
Methods
Accessors
androidId
• get androidId(): string
Settings.Secure.ANDROID_ID for the current user profile.
See also
https://developer.android.com/reference/android/provider/Settings.Secure#ANDROID_ID
Returns
string
battery
• get battery(): number
Battery level 0–100 (percentage).
Example
"nodejs";
const { device } = require("device");
console.log(device.battery);Returns
number
batteryPluggedTypes
• get batteryPluggedTypes(): PluggedType[]
Active power sources, e.g. ["usb"], ["ac"], or ["wireless", "usb"]. Empty array when unplugged.
Example
"nodejs";
const { device } = require("device");
console.log(device.batteryPluggedTypes);Returns
bootloader
• get bootloader(): string
Bootloader version string from Build.BOOTLOADER.
See also
https://developer.android.com/reference/android/os/Build.html#BOOTLOADER
Returns
string
brightness
• get brightness(): number
Screen brightness 0–255 (Settings.System.SCREEN_BRIGHTNESS).
"nodejs";
const { device } = require("device");
console.log(device.brightness);
device.brightness = 255;See also
https://developer.android.com/reference/android/provider/Settings.System#SCREEN_BRIGHTNESS
Returns
number
• set brightness(value): void
Parameters
| Name | Type |
|---|---|
value | number |
Returns
void
brightnessMode
• get brightnessMode(): BrightnessMode
Manual vs automatic brightness mode.
"nodejs";
const { device, BrightnessMode } = require("device");
console.log(device.brightnessMode);
device.brightnessMode = BrightnessMode.AUTOMATIC;See also
https://developer.android.com/reference/android/provider/Settings.System#SCREEN_BRIGHTNESS_MODE
Returns
• set brightnessMode(value): void
Parameters
| Name | Type |
|---|---|
value | BrightnessMode |
Returns
void
buildId
• get buildId(): string
Value of Build.ID.
See also
https://developer.android.com/reference/android/os/Build.html#ID
Returns
string
cpuApis
• get cpuApis(): string[]
Supported ABI list, e.g. ['arm64-v8a', 'armeabi-v7a'].
Returns
string[]
display
• get display(): string
Human-readable build string from Build.DISPLAY.
See also
https://developer.android.com/reference/android/os/Build.html#DISPLAY
Returns
string
displayMetrics
• get displayMetrics(): DisplayMetrics
Logical pixel size, density, scaled density, etc.
See also
Returns
externalStorageDirectory
• get externalStorageDirectory(): string
Primary shared / external storage root—the directory users treat as “SD card” space, even on devices without a removable card. It is world-readable in the classic model and may be mounted when the device is connected to a PC.
On multi-user devices each user has isolated shared storage; your process only sees the current user’s tree. When multiple physical volumes exist, this path is the primary volume users interact with; use Android APIs such as Context.getExternalFilesDirs, getExternalCacheDirs, or getExternalMediaDirs for secondary volumes.
Prefer Context.getExternalFilesDir (and similar) for app-private files so uninstall can wipe them. Put media meant for other apps under the appropriate public directory helpers instead of dumping files at this root.
Legacy read/write runtime permissions apply on older API levels; on modern releases prefer scoped storage APIs that do not require broad storage permission.
The absolute path may change across OS versions—store relative paths inside this tree if you must persist locations.
See also
https://developer.android.com/reference/android/os/Environment#getExternalStorageDirectory()
Returns
string
fingerprint
• get fingerprint(): string
Unique build fingerprint (Build.FINGERPRINT).
See also
https://developer.android.com/reference/android/os/Build.html#FINGERPRINT
Returns
string
hardware
• get hardware(): string
Hardware platform name (Build.HARDWARE).
See also
https://developer.android.com/reference/android/os/Build.html#HARDWARE
Returns
string
imei
• get imei(): null | string
IMEI when available and permitted. May throw if your app lacks carrier identifiers permission; from Android 10 ordinary apps generally cannot read IMEI.
See also
https://developer.android.com/reference/android/telephony/TelephonyManager#getDeviceId()
Returns
null | string
macAddress
• get macAddress(): null | string
Best-effort Wi-Fi MAC. Returns null when unavailable.
Note
From Android 6 (API 23) onward, non-privileged code usually sees a randomized placeholder such as 02:00:00:00:00:00, not the factory MAC.
Example
"nodejs";
const { device } = require("device");
const macAddress = device.macAddress;
if (macAddress) {
console.log("MAC:", macAddress);
} else {
console.log("MAC unavailable");
}Returns
null | string
memoryInfo
• get memoryInfo(): MemoryInfo
RAM summary: total, available, low-memory flag, etc. Values are in bytes.
Example
"nodejs";
const { device } = require("device");
console.log(`total: ${device.memoryInfo.totalMem / 1024 / 1024} MB`);
console.log(device.memoryInfo);See also
Returns
product
• get product(): Product
Marketing / SKU metadata: product name, device codename, board, brand, model.
Example
"nodejs";
const { device } = require("device");
console.log(device.product);
// {
// name: 'mars',
// device: 'mars',
// board: 'mars',
// brand: 'Xiaomi',
// model: 'M2102K1AC'
// }See also
https://developer.android.com/reference/android/os/Build.html#PRODUCT
Returns
screenHeight
• get screenHeight(): number
Default display height in pixels.
Returns
number
screenWidth
• get screenWidth(): number
Default display width in pixels.
Returns
number
serial
• get serial(): string
Hardware serial when exposed to the app. Access is restricted from Android 10 onward for most third-party packages.
See also
https://developer.android.com/reference/android/os/Build.html#getSerial()
Returns
string
Methods
cancelVibration
▸ cancelVibration(): void
Stop an ongoing vibration pattern.
See also
https://developer.android.com/reference/android/os/Vibrator.html#cancel()
Returns
void
getVolume
▸ getVolume(type): number
Current volume index for a stream, e.g. device.getVolume("music").
Parameters
| Name | Type | Description |
|---|---|---|
type | StreamType | Stream id (see StreamType). |
Returns
number
getVolumeRange
▸ getVolumeRange(type): StreamVolumeRange
Min/max indices for the stream, e.g. { min: 0, max: 15 }.
Parameters
| Name | Type | Description |
|---|---|---|
type | StreamType | Stream id. |
Returns
setVolume
▸ setVolume(type, volume, flags?): void
Set absolute index for a stream, e.g. device.setVolume("music", 10).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
type | StreamType | undefined | Stream id (see StreamType). |
volume | number | undefined | Target index within [min, max] from getVolumeRange. |
flags | string[] | [] | Optional hints such as SHOW_UI, PLAY_SOUND, VIBRATE. See AudioManager flag constants (e.g. FLAG_PLAY_SOUND). |
Returns
void
vibrate
▸ vibrate(millis): void
Vibrate for millis milliseconds. Typically requires the hosting app to be in the foreground (platform policy).
See also
https://developer.android.com/reference/android/os/Vibrator.html#vibrate(long)
Parameters
| Name | Type | Description |
|---|---|---|
millis | number | Duration in milliseconds. |
Returns
void
