diff --git a/zh-cn/application-dev/reference/apis/js-apis-bluetooth.md b/zh-cn/application-dev/reference/apis/js-apis-bluetooth.md index a956db4eeee7f610e443e8de72febd4cb5619aff..ce7214ccc18f0fccef021cff0f346bd490fad497 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-bluetooth.md +++ b/zh-cn/application-dev/reference/apis/js-apis-bluetooth.md @@ -1039,9 +1039,9 @@ let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE); ## bluetooth.getProfile9+ -getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile | HidHostProfile +getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile | HidHostProfile | PanProfile -通过ProfileId,获取profile的对象实例,API9新增了HidHostProfile。 +通过ProfileId,获取profile的对象实例,API9新增了HidHostProfile,PanProfile。 **系统能力**:SystemCapability.Communication.Bluetooth.Core。 @@ -1055,7 +1055,7 @@ getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfi | 类型 | 说明 | | ------------------------------------------------------------ | ------------------------------------------------------------ | -| [A2dpSourceProfile](#A2dpSourceProfile)或 [HandsFreeAudioGatewayProfile](#HandsFreeAudioGatewayProfile)或[HidHostProfile](#HidHostProfile) | 对应的profile的对象实例,当前支持A2dpSourceProfile/HandsFreeAudioGatewayProfile/HidHostProfile。 | +| [A2dpSourceProfile](#A2dpSourceProfile)或 [HandsFreeAudioGatewayProfile](#HandsFreeAudioGatewayProfile)或[HidHostProfile](#HidHostProfile)或[PanProfile](#PanProfile) | 对应的profile的对象实例,当前支持A2dpSourceProfile/HandsFreeAudioGatewayProfile/HidHostProfile/PanProfile。 | **示例:** @@ -1737,6 +1737,162 @@ hidHost.off('connectionStateChange', onReceiveEvent); ``` +## PanProfile + +使用PanProfile方法之前需要创建该类的实例进行操作,通过getProfile()方法构造此实例。 + + +### disconnect9+ + +disconnect(device: string): boolean + +断开连接设备的Pan服务。 + +此接口为系统接口。 + +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------- | +| device | string | 是 | 远端设备地址。 | + +**返回值:** + +| 类型 | 说明 | +| --------------------- | --------------------------------- | +| boolean | 成功返回true,失败返回false。 | + +**示例:** + +```js +let panProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_PAN_NETWORK); +let ret = panProfile.disconnect('XX:XX:XX:XX:XX:XX'); +``` + + +### on('connectionStateChange')9+ + +on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#StateChangeParam)>): void + +订阅Pan连接状态变化事件。 + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ---------------------------------------- | ---- | ---------------------------------------- | +| type | string | 是 | 填写"connectionStateChange"字符串,表示连接状态变化事件。 | +| callback | Callback<[StateChangeParam](#StateChangeParam)> | 是 | 表示回调函数的入参。 | + +**返回值:** + +无 + +**示例:** + +```js +function onReceiveEvent(data) { + console.info('pan state = '+ JSON.stringify(data)); +} +let panProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_PAN_NETWORK); +panProfile.on('connectionStateChange', onReceiveEvent); +``` + + +### off('connectionStateChange')9+ + +off(type: "connectionStateChange", callback?: Callback<[StateChangeParam](#StateChangeParam)>): void + +取消订阅Pan连接状态变化事件。 + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- | +| type | string | 是 | 填写"connectionStateChange"字符串,表示连接状态变化事件。 | +| callback | Callback<[StateChangeParam](#StateChangeParam)> | 否 | 表示回调函数的入参。 | + +**返回值:** + +无 + +**示例:** + +```js +function onReceiveEvent(data) { + console.info('pan state = '+ JSON.stringify(data)); +} +let panProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_PAN_NETWORK); +panProfile.on('connectionStateChange', onReceiveEvent); +panProfile.off('connectionStateChange', onReceiveEvent); +``` + + +### setTethering9+ + +setTethering(value: boolean): boolean + +设置网络共享状态。 + +此接口为系统接口。 + +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------- | +| value | boolean | 是 | 是否设置蓝牙共享。 | + +**返回值:** + +| 类型 | 说明 | +| --------------------- | --------------------------------- | +| boolean | 成功返回true,失败返回false。 | + +**示例:** + +```js +let panProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_PAN_NETWORK); +let ret = panProfile.setTethering(true); +``` + + +### isTetheringOn9+ + +isTetheringOn(): boolean + +获取网络共享状态。 + +此接口为系统接口。 + +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**返回值:** + +| 类型 | 说明 | +| --------------------- | --------------------------------- | +| boolean | 网络共享开启返回true,网络共享关闭返回false。 | + +**示例:** + +```js +let panProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_PAN_NETWORK); +let ret = panProfile.isTetheringOn(); +``` + + ## GattServer server端类,使用server端方法之前需要创建该类的实例进行操作,通过createGattServer()方法构造此实例。