openharmony 鸿蒙 js-apis-distributedHardwareManager-sys

2025-06-12 浏览 (1)

@ohos.distributedHardware.hardwareManager (Distributed Hardware Management) (System API)

The hardwareManager module provides the capability of controlling distributed hardware, including pausing, resuming, and stopping the distributed hardware service on the controlled device.

NOTE

The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.

The APIs provided by this module are system APIs.

Modules to Import

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

HardwareDescriptor

Represents the distributed hardware information.

System capability: SystemCapability.DistributedHardware.DistributedHardwareFWK

NameTypeMandatoryDescription
typeDistributedHardwareTypeYesType of the distributed hardware.
Required permissions: ohos.permission.ACCESS_DISTRIBUTED_HARDWARE
srcNetworkIdstringNoSource device. If this parameter is not specified, it indicates all source devices.
Required permissions: ohos.permission.ACCESS_DISTRIBUTED_HARDWARE

DistributedHardwareType

Enumerates the types of the distributed hardware.

System capability: SystemCapability.DistributedHardware.DistributedHardwareFWK

NameValueDescription
ALL0All distributed applications.
CAMERA1Distributed camera.
SCREEN8Distributed screen.
MODEM_MIC256Distributed microphone for mobile calls.
MODEM_SPEAKER512Distributed speaker for mobile calls.
MIC1024Distributed microphone.
SPEAKER2048Distributed speaker.

DistributedHardwareErrorCode

Enumerates the error codes used for the distributed hardware.

System capability: SystemCapability.DistributedHardware.DistributedHardwareFWK

NameValueDescription
ERR_CODE_DISTRIBUTED_HARDWARE_NOT_STARTED24200101The distributed hardware is not started.
ERR_CODE_DEVICE_NOT_CONNECTED24200102The source device is not connected.

hardwareManager.pauseDistributedHardware

pauseDistributedHardware(description: HardwareDescriptor): Promise<void>

Pauses the distributed hardware service on the controlled device. This API uses a promise to return the result.

Required permissions: ohos.permission.ACCESS_DISTRIBUTED_HARDWARE

System capability: SystemCapability.DistributedHardware.DistributedHardwareFWK

Parameters

NameTypeMandatoryDescription
descriptionHardwareDescriptorYesHardware information.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

IDError Message
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.

Example

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>

Resumes the distributed hardware service on the controlled device. This API uses a promise to return the result.

Required permissions: ohos.permission.ACCESS_DISTRIBUTED_HARDWARE

System capability: SystemCapability.DistributedHardware.DistributedHardwareFWK

Parameters

NameTypeMandatoryDescription
descriptionHardwareDescriptorYesHardware information.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

IDError Message
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.

Example

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>

Stops the distributed hardware service on the controlled device. This API uses a promise to return the result.

Required permissions: ohos.permission.ACCESS_DISTRIBUTED_HARDWARE

System capability: SystemCapability.DistributedHardware.DistributedHardwareFWK

Parameters

NameTypeMandatoryDescription
descriptionHardwareDescriptorYesHardware information.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

IDError Message
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.

Example

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 (Distributed Management Service)

harmony 鸿蒙DeviceManager

harmony 鸿蒙oh_device_manager_err_code.h

harmony 鸿蒙oh_device_manager.h

harmony 鸿蒙Device Management Error Codes

harmony 鸿蒙Screen Hopping Error Codes

harmony 鸿蒙Link Enhancement Error Codes

harmony 鸿蒙@ohos.distributedHardware.deviceManager (Device Management) (System API)

harmony 鸿蒙@ohos.cooperate (Screen Hopping) (System API)

harmony 鸿蒙@ohos.distributedsched.abilityConnectionManager (Cross-Device Connection Management) (System API)

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