Skip to main content

@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​

PropTypeDescription
modelstringDevice model (e.g. iPhone13,2).
platformstringPlatform: android / ios / mac / windows / web.
osVersionstringOperating system version.
manufacturerstringManufacturer.
isVirtualbooleanWhether this is an emulator/virtual device (DeviceType == Virtual).
namestringDevice name (provided by some platforms, may be empty).

GetLanguageCodeResult​

PropTypeDescription
valuestringCurrent UI language code (e.g. zh, en).

GetLocaleResult​

PropTypeDescription
valuestringCurrent locale (e.g. zh-CN).