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