メインコンテンツまでスキップ
バージョン: v2

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.

Example

import { Plugins } from '@capacitor/core';

const { Device } = Plugins;

const info = await Device.getInfo();
console.log(info);

// Example output:
{
"diskFree": 12228108288,
"appVersion": "1.0.2",
"appBuild": "123",
"appId": "com.capacitorjs.myapp",
"appName": "MyApp",
"operatingSystem": "ios",
"osVersion": "11.2",
"platform": "ios",
"memUsed": 93851648,
"diskTotal": 499054952448,
"model": "iPhone",
"manufacturer": "Apple",
"uuid": "84AE7AA1-7000-4696-8A74-4FD588A4A5C7",
"isVirtual":true
}

const info = await Device.getBatteryInfo();
console.log(info);

// Example output:
{
"batteryLevel": -1,
"isCharging": true
}

API

getInfo()

getInfo() => Promise<DeviceInfo>

Return information about the underlying device/os/platform

Returns:

Promise<DeviceInfo>


getBatteryInfo()

getBatteryInfo() => Promise<DeviceBatteryInfo>

Return information about the battery

Returns:

Promise<DeviceBatteryInfo>


getLanguageCode()

getLanguageCode() => Promise<DeviceLanguageCodeResult>

Get the device's current language locale code

Returns:

Promise<DeviceLanguageCodeResult>


Interfaces

DeviceInfo

PropTypeDescription
namestringNote: this property is iOS only. The name of the device. For example, "John's iPhone"
modelstringThe device model. For example, "iPhone"
platform"ios" | "android" | "electron" | "web"The device platform (lowercase).
uuidstringThe UUID of the device as available to the app. This identifier may change on modern mobile platforms that only allow per-app install UUIDs.
appVersionstringThe current bundle verison of the app
appBuildstringThe current bundle build of the app
appIdstringThe bundle id of the app
appNamestringThe display name of the app
operatingSystem"unknown" | "ios" | "android" | "windows" | "mac"The operating system of the device
osVersionstringThe version of the device OS
manufacturerstringThe manufacturer of the device
isVirtualbooleanWhether the app is running in a simulator/emulator
memUsednumberApproximate memory used by the current app, in bytes. Divide by 1048576 to get the number of MBs used.
diskFreenumberHow much free disk space is available on the the normal data storage path for the os, in bytes
diskTotalnumberThe total size of the normal data storage path for the OS, in bytes

DeviceBatteryInfo

PropTypeDescription
batteryLevelnumberA percentage (0 to 1) indicating how much the battery is charged
isChargingbooleanWhether the device is charging

DeviceLanguageCodeResult

PropType
valuestring