npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cordova-ohos/cordova-plugin-device

v3.0.0

Published

Cordova Device Plugin

Downloads

155

Readme

cordova-plugin-device

cordova-plugin-device 是 HarmonyOS Cordova 生态系统中的核心插件,用于获取当前运行应用的设备硬件信息与软件环境数据,为跨平台应用开发提供设备差异化适配能力,兼容Apache Cordova的Android、iOS 等主流移动平台及浏览器环境中使用,本文档只说明在HamronyOS系统中的使用。

插件简介

cordova-plugin-device 提供全局 device 对象,该对象在 Cordova 设备就绪事件(deviceready)触发后可用,可用于获取设备型号、操作系统版本、唯一标识符等关键信息

安装指南

通过 HCordova CLI 安装

在 Cordova 项目根目录执行以下命令,自动下载并集成插件:

#安装hcordova
npm install -g hcordova
#安装最新稳定版
hcordova plugin add cordova-plugin-device

#指定平台安装
hcordova plugin add cordova-plugin-device --platform ohos

#指定平台卸载
hcordova plugin remove cordova-plugin-device --platform ohos

核心 API:device 对象

device 是全局对象,必须在deviceready事件触发后使用(Cordova 插件初始化依赖该事件),未触发前调用会导致 deviceundefined

属性列表与说明

| 属性名 | 类型 | 描述 | | --------------------- | ------- | ---------------------------------------------------------------------------------------------------------------- | | device.model | String | 设备型号(认证型号,示例:ALN-AL00) | | device.platform | String | 设备操作系统名称(系统版本,版本格式OpenHarmony-x.x.x.x,x为数值) | | device.uuid | String | ODID,开发者匿名设备标识符| | device.version | String | 操作系统版本(版本ID:由deviceType、manufacture、brand、productSeries、osFullName、productModel、softwareModel、sdkApiVersion、incrementalVersion、buildType拼接组成。示例:wearable/HUAWEI/HUAWEI/TAS/OpenHarmony-5.0.0.1/TAS-AL00/TAS-AL00/12/default/release:nolog) | | device.manufacturer | String | 设备制造商(Huawei) | | device.isVirtual | Boolean | 标识设备是否为模拟器 / 虚拟设备(模拟器返回 true,真机返回 false) | | device.serial | String | ODID,开发者匿名设备标识符 |

使用示例

基础示例:获取设备信息并打印

在项目的 www/js/index.js 中添加以下代码,在设备就绪后获取并打印设备信息:

// 等待 Cordova 设备就绪事件

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
   console.log("Cordova 设备就绪,开始获取设备信息...");
   // 打印所有核心设备属性
   console.log("设备型号(model):", device.model);
   console.log("操作系统(platform):", device.platform);
   console.log("设备唯一标识(uuid):", device.uuid);
   console.log("系统版本(version):", device.version);
   console.log("设备制造商(manufacturer):", device.manufacturer);
   console.log("是否为虚拟设备(isVirtual):", device.isVirtual);
   console.log("设备序列号(serial):", device.serial);
}

常见问题(FAQ)

1. 为什么 uuid 会改变 ?

  • 原因:鸿蒙的 uuid 普通应用无法获取,因此返回的是ODID。

2. 虚拟机中 uuid和serial 为固定值?

  • 原因:鸿蒙的虚拟机中 uuid和serial 返回相同的值:emulator123456

参考资料

  1. 鸿蒙系统设备信息说明https://docs.openharmony.cn

  2. Android、ios插件说明www.npmjs.com

许可证

cordova-plugin-device 基于 Apache License 2.0 开源协议,可自由用于商业和非商业项目,协议全文见 Apache 官方网站