@napacitor/device
Device information plugin (corresponds to @capacitor/device).
Installation
To use npm:
npm install @napacitor/device
To use yarn:
yarn add @napacitor/device
Sync native files:
npx nap sync
Usage
import { Device } from '@napacitor/device';
const info = await Device.getInfo();
// { model, platform, osVersion, manufacturer, isVirtual, name? }
const lang = await Device.getLanguageCode(); // { value: 'zh' }
const locale = await Device.getLocale(); // { value: 'zh-CN' }
How It Works
Wraps the APIs described in the .NET MAUI DeviceInfo documentation: DeviceInfo.Current (Model / Manufacturer / Name / VersionString / DeviceType) and CultureInfo (language / region). isVirtual = DeviceType == Virtual; platform takes the Napacitor runtime platform name (android / ios / windows / mac).
Permissions
Android
No additional configuration required.
iOS
No additional configuration required.
Windows
No additional configuration required.
API
getInfo()
Gets device information.
Returns: Promise<DeviceInfo>
getLanguageCode()
Gets the current UI language code (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName).
Returns: Promise<GetLanguageCodeResult>
getLocale()
Gets the current locale (CultureInfo.CurrentCulture.Name).
Returns: Promise<GetLocaleResult>
Interfaces
DeviceInfo
| Prop | Type | Description |
|---|---|---|
model | string | Device model (e.g. iPhone13,2). |
platform | string | Platform: android / ios / mac / windows / web. |
osVersion | string | Operating system version. |
manufacturer | string | Manufacturer. |
isVirtual | boolean | Whether this is an emulator/virtual device (DeviceType == Virtual). |
name | string | Device name (provided by some platforms, may be empty). |
GetLanguageCodeResult
| Prop | Type | Description |
|---|---|---|
value | string | Current UI language code (e.g. zh, en). |
GetLocaleResult
| Prop | Type | Description |
|---|---|---|
value | string | Current locale (e.g. zh-CN). |