鸿蒙开发(NEXT/API 12)【穿戴设备信息查询】手机侧应用开发

复制代码
// 在使用Wear Engine服务前,请导入WearEngine与相关模块
import { wearEngine } from '@kit.WearEngine';
import { BusinessError } from '@kit.BasicServicesKit';

查询穿戴设备是否支持某种WearEngine能力集

注意

该接口的调用需要在开发者联盟申请设备基础信息权限。

通过Device对象中的方法isWearEngineCapabilitySupported查询穿戴设备是否支持某种WearEngine能力集。

  1. 应用调用wearEngine中的getDeviceClient方法,获取DeviceClient对象。

    复制代码
    let deviceClient: wearEngine.DeviceClient = wearEngine.getDeviceClient(getContext(this));
  2. 调用getConnectedDevices方法,获取已连接的设备列表。

    let deviceList: wearEngine.Device[] = [];
    deviceClient.getConnectedDevices().then(devices => {
    // 存储已连接的设备列表
    deviceList = devices;
    console.info(Succeeded in getting deviceList, devices number is ${deviceList.length});
    }).catch((error: BusinessError) => {
    // 处理调用失败时捕获到的异常
    console.error(Failed to get deviceList. Code is ${error.code}, message is ${error.message});
    })

  3. 从设备列表中选取需要操作的设备。

  4. 调用Device对象中的isWearEngineCapabilitySupported接口可查询该设备是否支持传入的WearEngine能力(true:支持;false:不支持),以P2P能力为例。

    if (deviceList.length > 0) {
    // 步骤3 从得到的设备列表中选取目标设备,并定义为device(假设数组中存在已连接设备且第一位即为目标设备)
    let targetDevice: wearEngine.Device = deviceList[0];

    // 步骤4 调用设备的方法查询是否支持某种WearEngine能力(以P2P为例)
    targetDevice.isWearEngineCapabilitySupported(wearEngine.WearEngineCapability.P2P_COMMUNICATION).then((isSupportP2P) => {
    console.info(Succeeded in checking p2p capability, result is ${isSupportP2P});
    }).catch((error: BusinessError) => {
    console.error(Failed to check p2p capability. Code is ${error.code}, message is ${error.message});
    })
    }

查询穿戴设备是否支持某种Device能力集

注意

该接口的调用需要在开发者联盟申请设备基础信息权限。

通过Device对象中的方法isDeviceCapabilitySupported查询穿戴设备是否支持某种Device能力集。

  1. 应用调用wearEngine中的getDeviceClient方法,获取DeviceClient对象。

    复制代码
    let deviceClient: wearEngine.DeviceClient = wearEngine.getDeviceClient(getContext(this));
  2. 调用getConnectedDevices方法,获取已连接的设备列表。

    let deviceList: wearEngine.Device[] = [];
    deviceClient.getConnectedDevices().then(devices => {
    // 存储已连接的设备列表
    deviceList = devices;
    console.info(Succeeded in getting deviceList, devices number is ${deviceList.length});
    }).catch((error: BusinessError) => {
    // 处理调用失败时捕获到的异常
    console.error(Failed to get deviceList. Code is ${error.code}, message is ${error.message});
    })

  3. 从设备列表中选取需要操作的设备。

  4. 调用Device对象中的isDeviceCapabilitySupported接口可查询该设备是否支持传入的Device能力(true:支持;false:不支持)。

    if (deviceList.length > 0) {
    // 步骤3 从得到的设备列表中选取目标设备,并定义为device(假设数组中存在已连接设备且第一位即为目标设备)
    let targetDevice: wearEngine.Device = deviceList[0];

    // 步骤4 调用设备的方法查询是否支持某种Device能力(以是否支持应用安装为例)
    targetDevice.isDeviceCapabilitySupported(wearEngine.DeviceCapability.APP_INSTALLATION).then((isSupportInstall) => {
    console.info(Succeeded in checking install app capability, result is ${isSupportInstall});
    }).catch((error: BusinessError) => {
    console.error(Failed to check install app capability. Code is ${error.code}, message is ${error.message});
    })
    }

查询设备SN

注意

该接口的调用需要在开发者联盟申请设备标识符权限(受限开放)并获得用户授权

通过Device对象中的方法getSerialNumber查询穿戴设备的SN。

  1. 应用调用wearEngine中的getDeviceClient方法,获取DeviceClient对象。

    复制代码
    let deviceClient: wearEngine.DeviceClient = wearEngine.getDeviceClient(getContext(this));
  2. 调用getConnectedDevices方法,获取已连接的设备列表。

    let deviceList: wearEngine.Device[] = [];
    deviceClient.getConnectedDevices().then(devices => {
    // 存储已连接的设备列表
    deviceList = devices;
    console.info(Succeeded in getting deviceList, devices number is ${deviceList.length});
    }).catch((error: BusinessError) => {
    // 处理调用失败时捕获到的异常
    console.error(Failed to get deviceList. Code is ${error.code}, message is ${error.message});
    })

  3. 从设备列表中选取需要操作的设备。

  4. 调用Device对象中的方法getSerialNumber查询穿戴设备的SN。

    if (deviceList.length > 0) {
    // 步骤3 从得到的设备列表中选取目标设备,并定义为device(假设数组中存在已连接设备且第一位即为目标设备)
    let targetDevice: wearEngine.Device = deviceList[0];

    // 步骤4 调用设备的方法查询SN
    targetDevice.getSerialNumber().then((sn) => {
    console.info(Succeeded in getting device SN, result is ${sn});
    }).catch((error: BusinessError) => {
    console.error(Failed to get device SN. Code is ${error.code}, message is ${error.message});
    })
    }

最后呢

很多开发朋友不知道需要学习那些鸿蒙技术?鸿蒙开发岗位需要掌握那些核心技术点?为此鸿蒙的开发学习必须要系统性的进行。

而网上有关鸿蒙的开发资料非常的少,假如你想学好鸿蒙的应用开发与系统底层开发。你可以参考这份资料,少走很多弯路,节省没必要的麻烦。由两位前阿里高级研发工程师联合打造的《鸿蒙NEXT星河版OpenHarmony开发文档 》里面内容包含了(ArkTS、ArkUI开发组件、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战等等)鸿蒙(Harmony NEXT)技术知识点

如果你是一名Android、Java、前端等等开发人员,想要转入鸿蒙方向发展。可以直接领取这份资料辅助你的学习。下面是鸿蒙开发的学习路线图。

针对鸿蒙成长路线打造的鸿蒙学习文档。话不多说,我们直接看详细鸿蒙(OpenHarmony )手册(共计1236页)与鸿蒙(OpenHarmony )开发入门视频,帮助大家在技术的道路上更进一步。

  • 《鸿蒙 (OpenHarmony)开发学习视频》
  • 《鸿蒙生态应用开发V2.0白皮书》
  • 《鸿蒙 (OpenHarmony)开发基础到实战手册》
  • OpenHarmony北向、南向开发环境搭建
  • 《鸿蒙开发基础》
  • 《鸿蒙开发进阶》
  • 《鸿蒙开发实战》

总结

鸿蒙---作为国家主力推送的国产操作系统。部分的高校已经取消了安卓课程,从而开设鸿蒙课程;企业纷纷跟进启动了鸿蒙研发。

并且鸿蒙是完全具备无与伦比的机遇和潜力的;预计到年底将有 5,000 款的应用完成原生鸿蒙开发,未来将会支持 50 万款的应用。那么这么多的应用需要开发,也就意味着需要有更多的鸿蒙人才。鸿蒙开发工程师也将会迎来爆发式的增长,学习鸿蒙势在必行! 自↓↓↓拿

相关推荐
花椒技术6 小时前
复杂直播业务做 RN 跨端,我们最后保留了哪些 Native 边界
react native·react.js·harmonyos
智者知已应修善业7 小时前
【proteus设计文氏正弦波信号发生器】2023-5-9
驱动开发·经验分享·笔记·硬件架构·proteus·硬件工程
LCG元8 小时前
STM32实战:基于STM32F103的家用新风系统智能控制器(空气质量监测+PID调速)
stm32·单片机·嵌入式硬件
不羁的木木8 小时前
《HarmonyOS技术精讲》四:驱动开发入门 ── 标准外设与非标USB串口
驱动开发·华为·harmonyos
LCG元9 小时前
STM32实战:基于STM32F103的多通道工业数据采集与监控系统(Modbus RTU+上位机)
stm32·单片机·嵌入式硬件
资深流水灯工程师9 小时前
STM32 单片机 USB 通讯原理与 HAL 库实战详解
stm32·单片机·嵌入式硬件
不羁的木木9 小时前
《HarmonyOS底部页签-沉浸光感组件实战》高级定制:图标出血与分割线
华为·harmonyos
资深流水灯工程师9 小时前
STM32 I2C 通讯原理与三种实现模式详解
stm32·单片机·嵌入式硬件
zlinear数据采集卡9 小时前
电源纹波杀手:LDO线性稳压电路的“降噪哲学”——基于ZLinear数据采集卡的深度解析
单片机·嵌入式硬件·fpga开发·硬件架构
资深流水灯工程师9 小时前
STM32 USART 通讯原理与三种模式详解
stm32·单片机·嵌入式硬件