• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bluetooth.pan (Bluetooth pan Module)
2
3The **pan** module provides APIs for accessing the Bluetooth personal area network (PAN).
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9
10
11## Modules to Import
12
13```js
14import pan from '@ohos.bluetooth.pan';
15```
16
17
18## pan.createPanProfile<a name="createPanProfile"></a>
19
20createPanProfile(): PanProfile
21
22Creates a **PanProfile** instance.
23
24**System capability**: SystemCapability.Communication.Bluetooth.Core
25
26**Return value**
27
28| Type                           | Description        |
29| ----------------------------- | ---------- |
30| PanProfile | **PanProfile** instance created.|
31
32**Example**
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
47Before using any API of **PanProfile**, you need to create an instance of this class by using **createPanProfile()**.
48
49
50### disconnect<a name="PanP-disconnect"></a>
51
52disconnect(deviceId: string): void
53
54Disconnects from the PAN service of a device.
55
56**System API**: This is a system API.
57
58**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
59
60**System capability**: SystemCapability.Communication.Bluetooth.Core
61
62**Parameters**
63
64| Name   | Type    | Mandatory  | Description     |
65| ------ | ------ | ---- | ------- |
66| deviceId | string | Yes   | Address of the remote device.|
67
68**Error codes**
69
70For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
71
72| ID| Error Message|
73| -------- | ---------------------------- |
74|2900001 | Service stopped.                         |
75|2900003 | Bluetooth switch is off.                 |
76|2900004 | Profile is not supported.                |
77|2900099 | Operation failed.                        |
78
79**Example**
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
96Sets Bluetooth tethering, which shares a mobile connection.
97
98**System API**: This is a system API.
99
100**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
101
102**System capability**: SystemCapability.Communication.Bluetooth.Core
103
104**Parameters**
105
106| Name   | Type    | Mandatory  | Description     |
107| ------ | ------ | ---- | ------- |
108| value | boolean | Yes   | Whether to set tethering over a Bluetooth PAN.|
109
110**Error codes**
111
112For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
113
114| ID| Error Message|
115| -------- | ---------------------------- |
116|2900001 | Service stopped.                         |
117|2900003 | Bluetooth switch is off.                 |
118|2900004 | Profile is not supported.                |
119|2900099 | Operation failed.                        |
120
121**Example**
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
138Checks whether Bluetooth tethering is activated.
139
140**System API**: This is a system API.
141
142**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
143
144**System capability**: SystemCapability.Communication.Bluetooth.Core
145
146**Return value**
147
148| Type     | Description                 |
149| --------------------- | --------------------------------- |
150| boolean | Returns **true** if tethering is available over a Bluetooth PAN; returns **false** otherwise.|
151
152**Example**
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```
163