@capacitor/device
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.
Install
npm install @capacitor/device
npx cap sync
Example
import { Device } from '@capacitor/device';
const logDeviceInfo = async () => {
const info = await Device.getInfo();
console.log(info);
};
const logBatteryInfo = async () => {
const info = await Device.getBatteryInfo();
console.log(info);
};
API
getId()
getId() => Promise<DeviceId>
Return an unique identifier for the device.
Returns:
Promise<DeviceId>
Since: 1.0.0
getInfo()
getInfo() => Promise<DeviceInfo>
Return information about the underlying device/os/platform.
Returns:
Promise<DeviceInfo>
Since: 1.0.0
getBatteryInfo()
getBatteryInfo() => Promise<BatteryInfo>
Return information about the battery.
Returns:
Promise<BatteryInfo>
Since: 1.0.0
getLanguageCode()
getLanguageCode() => Promise<GetLanguageCodeResult>
Get the device's current language locale code.
Returns:
Promise<GetLanguageCodeResult>
Since: 1.0.0
getLanguageTag()
getLanguageTag() => Promise<LanguageTag>
Get the device's current language locale tag.
Returns:
Promise<LanguageTag>
Since: 4.0.0
Interfaces
DeviceId
Prop | Type | Description | Since |
---|---|---|---|
uuid | string | The UUID of the device as available to the app. This identifier may change on modern mobile platforms that only allow per-app install UUIDs. On web, a random identifier is generated and stored on localStorage for subsequent calls. If localStorage is not available a new random identifier will be generated on every call. | 1.0.0 |