openharmony 鸿蒙 js-apis-fusionConnectivity-partnerAgent-sys

2026-08-25 浏览 (1)

@ohos.FusionConnectivity.partnerAgent(设备状态通知模块)(系统接口)

本模块基于蓝牙通信技术,为应用提供设备发现与设备下线的通知功能,主要功能特性包括:

说明:

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

导入模块

import { partnerAgent } from '@kit.ConnectivityKit';

partnerAgent.enableDeviceControl

enableDeviceControl(deviceAddress: PartnerDeviceAddress): Promise<void>

开启外设互通功能,使用Promise异步回调。

系统接口:此接口为系统接口。

需要权限:ohos.permission.ACCESS_BLUETOOTH

系统能力:SystemCapability.Communication.FusionConnectivity.Core

参数

参数名类型必填说明
deviceAddressPartnerDeviceAddress应用注册的设备地址信息。
应用需配置PartnerDeviceAddress类型的bluetoothAddress选项。

返回值

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

错误码

以下错误码的详细介绍请参考通用错误码说明文档融合短距服务子系统错误码

错误码ID错误信息
201Permission denied.
202Non-system applications are not allowed to use system APIs.
801Capability not supported.
34900001The device is not bound.
34900099Internal error.

示例

import { partnerAgent, common } from '@kit.ConnectivityKit';
try {
  let btAddr: common.BluetoothAddress = {
    "address": "11:22:33:44:55:66",
    "addressType": common.BluetoothAddressType.REAL,
  };
  let deviceAddress: partnerAgent.PartnerDeviceAddress = {
    "bluetoothAddress": btAddr,
  };
  partnerAgent.enableDeviceControl(deviceAddress)
    .then(() => {
      console.info(`enable device control success: ${btAddr.address}`);
    })
    .catch((err: BusinessError) => {
      console.error(`errCode: ${err.code}, errMessage: ${err.message}`);
    });
} catch (err) {
  console.error(`errCode: ${err.code}, errMessage: ${err.message}`);
}

partnerAgent.disableDeviceControl

disableDeviceControl(deviceAddress: PartnerDeviceAddress): Promise<void>

关闭外设互通功能,使用Promise异步回调。

系统接口:此接口为系统接口。

需要权限:ohos.permission.ACCESS_BLUETOOTH

系统能力:SystemCapability.Communication.FusionConnectivity.Core

参数

参数名类型必填说明
deviceAddressPartnerDeviceAddress应用注册的设备地址信息。
应用需配置PartnerDeviceAddress类型的bluetoothAddress选项。

返回值

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

错误码

以下错误码的详细介绍请参考通用错误码说明文档融合短距服务子系统错误码

错误码ID错误信息
201Permission denied.
202Non-system applications are not allowed to use system APIs.
801Capability not supported.
34900001The device is not bound.
34900099Internal error.

示例

import { partnerAgent, common } from '@kit.ConnectivityKit';
try {
  let btAddr: common.BluetoothAddress = {
    "address": "11:22:33:44:55:66",
    "addressType": common.BluetoothAddressType.REAL,
  };
  let deviceAddress: partnerAgent.PartnerDeviceAddress = {
    "bluetoothAddress": btAddr,
  };
  partnerAgent.disableDeviceControl(deviceAddress)
    .then(() => {
      console.info(`disable device control success: ${btAddr.address}`);
    })
    .catch((err: BusinessError) => {
      console.error(`errCode: ${err.code}, errMessage: ${err.message}`);
    });
} catch (err) {
  console.error(`errCode: ${err.code}, errMessage: ${err.message}`);
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 js-apis-bluetooth-a2dp

openharmony 鸿蒙 js-apis-bluetooth-map

openharmony 鸿蒙 capi-oh-bluetooth-h

openharmony 鸿蒙 js-apis-nfcTag

openharmony 鸿蒙 js-apis-wifiManagerExt

openharmony 鸿蒙 js-apis-bluetooth-ble

openharmony 鸿蒙 errorcode-wifi

openharmony 鸿蒙 capi-bluetooth

openharmony 鸿蒙 js-apis-wifiext

openharmony 鸿蒙 js-apis-bluetooth-baseProfile-sys

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