openharmony 鸿蒙 js-apis-fusionConnectivity-partnerAgentExtensionAbility

2026-08-25 浏览 (1)

@ohos.FusionConnectivity.PartnerAgentExtensionAbility (ExtensionAbility Component Supporting Device Status Notifications)

As the base class of the peripheral interconnection extension capability, PartnerAgentExtensionAbility provides the device discovery and device offline notification features. This class needs to be inherited by the application. The type attribute of extensionAbilities in the module-level configuration file module.json5 must be set to partnerAgent.

NOTE

  • The initial APIs of this module are supported since API version 23. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • The APIs of this module can be used only in the stage model.

Modules to Import

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

PartnerDeviceAddress

type PartnerDeviceAddress = partnerAgent.PartnerDeviceAddress

Describes the device address information.

System capability: SystemCapability.Communication.FusionConnectivity.Core

Model restriction: This API can be used only in the stage model.

TypeDescription
partnerAgent.PartnerDeviceAddressAddress of the device to be interconnected.

PartnerAgentExtensionAbilityDestroyReason

type PartnerAgentExtensionAbilityDestroyReason = partnerAgent.PartnerAgentExtensionAbilityDestroyReason

Describes the reason why PartnerAgentExtensionAbility is destroyed.

System capability: SystemCapability.Communication.FusionConnectivity.Core

Model restriction: This API can be used only in the stage model.

TypeDescription
partnerAgent.PartnerAgentExtensionAbilityDestroyReasonReason why PartnerAgentExtensionAbility is destroyed.

PartnerAgentExtensionAbility

As the base class of the peripheral interconnection extension capability, PartnerAgentExtensionAbility provides the device discovery and device offline notification features. This class needs to be inherited by the application. It is inherited from ExtensionAbility.

Attribute

System capability: SystemCapability.Communication.FusionConnectivity.Core

Model restriction: This API can be used only in the stage model.

NameTypeRead-OnlyOptionalDescription
contextPartnerAgentExtensionContextNoNoContext of PartnerAgentExtensionAbility.

onDestroyWithReason

onDestroyWithReason(reason: PartnerAgentExtensionAbilityDestroyReason): void

Called when the peripheral interconnection extension capability is destroyed.

System capability: SystemCapability.Communication.FusionConnectivity.Core

Model restriction: This API can be used only in the stage model.

Parameters

NameTypeMandatoryDescription
reasonPartnerAgentExtensionAbilityDestroyReasonYesDestruction reason.

Example

export default class PartnerAgentExtAbility extends PartnerAgentExtensionAbility {
  onDestroyWithReason(reason: partnerAgent.PartnerAgentExtensionAbilityDestroyReason): void {
    console.info(`onDestroyWithReason is: ${reason}`);
  }
}

onDeviceDiscovered

onDeviceDiscovered(deviceAddress: PartnerDeviceAddress): void

Called when a registered device is discovered.

System capability: SystemCapability.Communication.FusionConnectivity.Core

Model restriction: This API can be used only in the stage model.

Parameters

NameTypeMandatoryDescription
deviceAddressPartnerDeviceAddressYesAddress information of the device registered by the application.
The application must be configured with the bluetoothAddress option of the PartnerDeviceAddress type.

Example

export default class PartnerAgentExtAbility extends PartnerAgentExtensionAbility {
  onDeviceDiscovered(deviceAddress: partnerAgent.PartnerDeviceAddress): void {
    console.info(`onDeviceDiscovered success: ${deviceAddress.bluetoothAddress}`);
  }
}

你可能感兴趣的鸿蒙文章

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-fusionConnectivity-partnerAgent-sys

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