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