openharmony 鸿蒙 js-apis-distributedHardwareManager-sys

2025-06-12 浏览 (1)

@ohos.distributedHardware.hardwareManager (分布式硬件管理)(系统接口)

分布式硬件管理模块提供控制分布式硬件的能力,包括暂停、恢复和停止被控端分布式硬件业务。

说明:

本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

本模块接口为系统接口。

导入模块

import hardwareManager from '@ohos.distributedHardware.hardwareManager';

HardwareDescriptor

表示分布式硬件的描述信息。

系统能力:SystemCapability.DistributedHardware.DistributedHardwareFWK

名称类型必填说明
typeDistributedHardwareType分布式硬件类型。
需要权限:ohos.permission.ACCESS_DISTRIBUTED_HARDWARE
srcNetworkIdstring表示源端设备,缺省时表示所有源端设备。
需要权限:ohos.permission.ACCESS_DISTRIBUTED_HARDWARE

DistributedHardwareType

表示分布式硬件类型。

系统能力:SystemCapability.DistributedHardware.DistributedHardwareFWK

名称说明
ALL0表示所有分布式应用。
CAMERA1表示分布式相机。
SCREEN8表示分布式屏幕。
MODEM_MIC256表示分布式移动通话的麦克风。
MODEM_SPEAKER512表示分布式移动通话的扬声器。
MIC1024表示分布式麦克风。
SPEAKER2048表示分布式扬声器。

DistributedHardwareErrorCode

分布式硬件错误码的枚举。

系统能力:SystemCapability.DistributedHardware.DistributedHardwareFWK

名称说明
ERR_CODE_DISTRIBUTED_HARDWARE_NOT_STARTED24200101表示分布式硬件未启动。
ERR_CODE_DEVICE_NOT_CONNECTED24200102表示源端设备未连接。

hardwareManager.pauseDistributedHardware

pauseDistributedHardware(description: HardwareDescriptor): Promise<void>

暂停被控端分布式硬件业务。使用promise异步回调。

需要权限:ohos.permission.ACCESS_DISTRIBUTED_HARDWARE

系统能力:SystemCapability.DistributedHardware.DistributedHardwareFWK

参数:

参数名类型必填说明
descriptionHardwareDescriptor硬件描述信息。

返回值:

类型说明
Promise<void>无返回结果的Promise对象。

错误码:

错误码ID错误信息
201Permission verification failed.
202Permission denied, non-system app called system api.
401Input parameter error.
24200101The specified distributed hardware is not started.
24200102The specified source device is not connected.

示例:

import hardwareManager from '@ohos.distributedHardware.hardwareManager';
import { BusinessError } from '@ohos.base';

try {
  let description: hardwareManager.HardwareDescriptor = {
    type: 1,
    srcNetworkId: '1111'
  };
  hardwareManager.pauseDistributedHardware(description).then(() => {
    console.log('pause distributed hardware successfully');
  }).catch((error: BusinessError) => {
    console.error('pause distributed hardware failed, cause:' + error);
  })
  console.log('pause distributed hardware successfully');
} catch (error) {
  console.error('pause distributed hardware failed:' + error);
}

hardwareManager.resumeDistributedHardware

resumeDistributedHardware(description: HardwareDescriptor): Promise<void>

恢复被控端分布式硬件业务。使用promise异步回调。

需要权限:ohos.permission.ACCESS_DISTRIBUTED_HARDWARE

系统能力:SystemCapability.DistributedHardware.DistributedHardwareFWK

参数:

参数名类型必填说明
descriptionHardwareDescriptor硬件描述信息。

返回值:

类型说明
Promise<void>无返回结果的Promise对象。

错误码:

错误码ID错误信息
201Permission verification failed.
202Permission denied, non-system app called system api.
401Input parameter error.
24200101The specified distributed hardware is not started.
24200102The specified source device is not connected.

示例:

import hardwareManager from '@ohos.distributedHardware.hardwareManager';
import { BusinessError } from '@ohos.base';

try {
  let description: hardwareManager.HardwareDescriptor = {
    type: 1,
    srcNetworkId: '1111'
  };
  hardwareManager.resumeDistributedHardware(description).then(() => {
    console.log('resume distributed hardware successfully');
  }).catch((error: BusinessError) => {
    console.error('resume distributed hardware failed, cause:' + error);
  })
  console.log('resume distributed hardware successfully');
} catch (error) {
  console.error('resume distributed hardware failed:' + error);
}


hardwareManager.stopDistributedHardware

stopDistributedHardware(description: HardwareDescriptor): Promise<void>

停止被控端分布式硬件业务。使用promise异步回调。

需要权限:ohos.permission.ACCESS_DISTRIBUTED_HARDWARE

系统能力:SystemCapability.DistributedHardware.DistributedHardwareFWK

参数:

参数名类型必填说明
descriptionHardwareDescriptor硬件描述信息。

返回值:

类型说明
Promise<void>无返回结果的Promise对象。

错误码:

错误码ID错误信息
201Permission verification failed.
202Permission denied, non-system app called system api.
401Input parameter error.
24200101The specified distributed hardware is not started.
24200102The specified source device is not connected.

示例:

import hardwareManager from '@ohos.distributedHardware.hardwareManager';
import { BusinessError } from '@ohos.base';

try {
  let description: hardwareManager.HardwareDescriptor = {
    type: 1,
    srcNetworkId: '1111'
  };
  hardwareManager.stopDistributedHardware(description).then(() => {
    console.log('stop distributed hardware successfully');
  }).catch((error: BusinessError) => {
    console.error('stop distributed hardware failed, cause:' + error);
  })
  console.log('stop distributed hardware successfully');
} catch (error) {
  console.error('stop distributed hardware failed:' + error);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Distributed Service Kit(分布式管理服务)

harmony 鸿蒙DeviceManager

harmony 鸿蒙oh_device_manager_err_code.h

harmony 鸿蒙oh_device_manager.h

harmony 鸿蒙设备管理错误码

harmony 鸿蒙键鼠穿越管理错误码

harmony 鸿蒙增强连接错误码

harmony 鸿蒙@ohos.distributedHardware.deviceManager (设备管理)(系统接口)

harmony 鸿蒙@ohos.cooperate (键鼠穿越)(系统接口)

harmony 鸿蒙@ohos.distributedsched.abilityConnectionManager (应用多端协同管理)(系统接口)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/DF8pgd