• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 '@ohos.bluetooth.pan';
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.Core32
33**参数:**
34
35| 参数名    | 类型     | 必填   | 说明      |
36| ------ | ------ | ---- | ------- |
37| deviceId | string | 是    | 远端设备地址。 |
38
39**错误码**:
40
41以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
42
43| 错误码ID | 错误信息 |
44| -------- | ---------------------------- |
45|2900001 | Service stopped.                         |
46|2900003 | Bluetooth switch is off.                 |
47|2900004 | Profile is not supported.                |
48|2900099 | Operation failed.                        |
49
50**示例:**
51
52```js
53import { BusinessError } from '@ohos.base';
54try {
55    let panProfile: pan.PanProfile = pan.createPanProfile();
56    panProfile.disconnect('XX:XX:XX:XX:XX:XX');
57} catch (err) {
58    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
59}
60```
61
62
63### setTethering
64
65setTethering(enable: boolean): void
66
67设置网络共享状态。
68
69**系统接口**:此接口为系统接口。
70
71**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
72
73**系统能力**:SystemCapability.Communication.Bluetooth.Core74
75**参数:**
76
77| 参数名    | 类型     | 必填   | 说明      |
78| ------ | ------ | ---- | ------- |
79| value | boolean | 是    | 是否设置蓝牙共享。 |
80
81**错误码**:
82
83以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
84
85| 错误码ID | 错误信息 |
86| -------- | ---------------------------- |
87|2900001 | Service stopped.                         |
88|2900003 | Bluetooth switch is off.                 |
89|2900004 | Profile is not supported.                |
90|2900099 | Operation failed.                        |
91
92**示例:**
93
94```js
95import { BusinessError } from '@ohos.base';
96try {
97    let panProfile: pan.PanProfile = pan.createPanProfile();
98    panProfile.setTethering(false);
99} catch (err) {
100    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
101}
102```
103
104
105### isTetheringOn
106
107isTetheringOn(): boolean
108
109获取网络共享状态。
110
111**系统接口**:此接口为系统接口。
112
113**需要权限**:ohos.permission.ACCESS_BLUETOOTH
114
115**系统能力**:SystemCapability.Communication.Bluetooth.Core116
117**返回值:**
118
119| 类型      | 说明                  |
120| --------------------- | --------------------------------- |
121| boolean | 网络共享开启返回true,网络共享关闭返回false。 |
122
123**示例:**
124
125```js
126import { BusinessError } from '@ohos.base';
127try {
128    let panProfile: pan.PanProfile = pan.createPanProfile();
129    panProfile.isTetheringOn();
130} catch (err) {
131    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
132}
133```