Device
#Overview
The Device API exposes internal information about the device, such as the model and operating system version, along with user information such as unique ids.
Import
Copied!
use Native\Mobile\Facades\Device;
Copied!
import { device } from '#nativephp';
#Methods
#getId()
Return a unique identifier for the device.
Returns: string
Get Device ID
Copied!
$id = Device::getId();
Copied!
const result = await device.getId();const deviceId = result.id;
#getInfo()
Return information about the underlying device/os/platform.
Returns JSON encoded: string
Get Device Info
Copied!
$info = Device::getInfo();$deviceInfo = json_decode($info);
Copied!
const result = await device.getInfo();const deviceInfo = JSON.parse(result.info); console.log(deviceInfo.platform); // 'ios' or 'android'console.log(deviceInfo.model); // e.g., 'iPhone13,4'console.log(deviceInfo.osVersion); // e.g., '17.0'
#vibrate()
Triggers device vibration for tactile feedback.
Returns: void
Vibrate
Copied!
Device::vibrate();
Copied!
await device.vibrate();
#flashlight()
Toggles the device flashlight (camera flash LED) on and off.
Returns: void
Toggle Flashlight
Copied!
Device::flashlight(); // Toggle flashlight state
Copied!
const result = await device.flashlight();console.log(result.state); // true = on, false = off
#getBatteryInfo()
Return information about the battery.
Returns JSON encoded: string
Get Battery Info
Copied!
$info = Device::getBatteryInfo();$batteryInfo = json_decode($info);
Copied!
const result = await device.getBatteryInfo();const batteryInfo = JSON.parse(result.info); console.log(batteryInfo.batteryLevel); // 0-1 (e.g., 0.85 = 85%)console.log(batteryInfo.isCharging); // true/false
#Device Info
| Prop | Type | Description |
|---|---|---|
| name | string | The name of the device. For example, "John's iPhone". On iOS 16+ this will return a generic device name without the appropriate entitlements. |
| model | string | The device model. For example, "iPhone13,4". |
| platform | 'ios' | 'android' | The device platform (lowercase). |
| operatingSystem | string | The operating system of the device. |
| osVersion | string | The version of the device OS. |
| iOSVersion | number | The iOS version number. Only available on iOS. Multi-part version numbers are crushed down into an integer padded to two-digits, e.g., "16.3.1" → 160301. |
| androidSDKVersion | number | The Android SDK version number. Only available on Android. |
| manufacturer | string | The manufacturer of the device. |
| isVirtual | boolean | Whether the app is running in a simulator/emulator. |
| memUsed | number | Approximate memory used by the current app, in bytes. Divide by 1,048,576 to get MBs used. |
| webViewVersion | string | The web view browser version. |
#Battery Info
| Prop | Type | Description |
|---|---|---|
| batteryLevel | number | A percentage (0 to 1) indicating how much the battery is charged. |
| isCharging | boolean | Whether the device is charging. |