1# @ohos.bluetooth.pan (蓝牙pan模块)(系统接口) 2 3pan模块提供了访问蓝牙个人区域网相关功能的方法。 4 5> **说明:** 6> 7> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.bluetooth.pan (蓝牙pan模块)](js-apis-bluetooth-pan.md) 9 10 11## 导入模块 12 13```js 14import { pan } from '@kit.ConnectivityKit'; 15``` 16 17## PanProfile 18 19使用PanProfile方法之前需要创建该类的实例进行操作,通过createPanProfile()方法构造此实例。 20 21### disconnect 22 23disconnect(deviceId: string): void 24 25断开连接设备的Pan服务。 26 27**系统接口**:此接口为系统接口。 28 29**需要权限**:ohos.permission.ACCESS_BLUETOOTH 30 31**系统能力**:SystemCapability.Communication.Bluetooth.Core。 32 33**参数:** 34 35| 参数名 | 类型 | 必填 | 说明 | 36| ------ | ------ | ---- | ------- | 37| deviceId | string | 是 | 远端设备地址。 | 38 39**错误码**: 40 41以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 42 43| 错误码ID | 错误信息 | 44| -------- | ---------------------------- | 45|201 | Permission denied. | 46|202 | Non-system applications are not allowed to use system APIs. | 47|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 48|801 | Capability not supported. | 49|2900001 | Service stopped. | 50|2900003 | Bluetooth disabled. | 51|2900004 | Profile not supported. | 52|2900099 | Operation failed. | 53 54**示例:** 55 56```js 57import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 58try { 59 let panProfile: pan.PanProfile = pan.createPanProfile(); 60 panProfile.disconnect('XX:XX:XX:XX:XX:XX'); 61} catch (err) { 62 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 63} 64``` 65 66 67### setTethering 68 69setTethering(enable: boolean): void 70 71设置网络共享状态。 72 73**系统接口**:此接口为系统接口。 74 75**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 76 77**系统能力**:SystemCapability.Communication.Bluetooth.Core。 78 79**参数:** 80 81| 参数名 | 类型 | 必填 | 说明 | 82| ------ | ------ | ---- | ------- | 83| value | boolean | 是 | 是否设置蓝牙共享。true表示设置蓝牙共享,false表示不设置蓝牙共享。 | 84 85**错误码**: 86 87以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 88 89| 错误码ID | 错误信息 | 90| -------- | ---------------------------- | 91|201 | Permission denied. | 92|202 | Non-system applications are not allowed to use system APIs. | 93|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 94|801 | Capability not supported. | 95|2900001 | Service stopped. | 96|2900003 | Bluetooth disabled. | 97|2900004 | Profile not supported. | 98|2900099 | Operation failed. | 99 100**示例:** 101 102```js 103import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 104try { 105 let panProfile: pan.PanProfile = pan.createPanProfile(); 106 panProfile.setTethering(false); 107} catch (err) { 108 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 109} 110``` 111 112 113### isTetheringOn 114 115isTetheringOn(): boolean 116 117获取网络共享状态。 118 119**系统接口**:此接口为系统接口。 120 121**需要权限**:ohos.permission.ACCESS_BLUETOOTH 122 123**系统能力**:SystemCapability.Communication.Bluetooth.Core。 124 125**返回值:** 126 127| 类型 | 说明 | 128| --------------------- | --------------------------------- | 129| boolean | 网络共享开启返回true,网络共享关闭返回false。 | 130 131**错误码**: 132 133以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 134 135| 错误码ID | 错误信息 | 136| -------- | ---------------------------- | 137|201 | Permission denied. | 138|202 | Non-system applications are not allowed to use system APIs. | 139|801 | Capability not supported. | 140 141 142**示例:** 143 144```js 145import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 146try { 147 let panProfile: pan.PanProfile = pan.createPanProfile(); 148 panProfile.isTetheringOn(); 149} catch (err) { 150 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 151} 152```