• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bluetooth.connection (Bluetooth connection Module)
2
3The **connection** module provides APIs for operating and managing Bluetooth.
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 connection from '@ohos.bluetooth.connection';
15import { BusinessError } from '@ohos.base';
16```
17
18
19## connection.pairDevice<a name="pairDevice"></a>
20
21pairDevice(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
22
23Pairs a Bluetooth device. This API uses an asynchronous callback to return the result.
24
25**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
26
27**System capability**: SystemCapability.Communication.Bluetooth.Core
28
29**Parameters**
30
31| Name     | Type    | Mandatory  | Description                                 |
32| -------- | ------ | ---- | ----------------------------------- |
33| deviceId | string | Yes   | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.|
34| callback | AsyncCallback&lt;void&gt;  | Yes   | Callback invoked to return the result. If the pairing is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
35
36**Error codes**
37
38For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
39
40| ID| Error Message|
41| -------- | ---------------------------- |
42|2900001 | Service stopped.                         |
43|2900003 | Bluetooth switch is off.                 |
44|2900099 | Operation failed.                        |
45
46**Example**
47
48```js
49try {
50    // The address can be scanned.
51    connection.pairDevice('XX:XX:XX:XX:XX:XX');
52} catch (err) {
53    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
54}
55```
56
57
58## connection.pairDevice<a name="pairDevice"></a>
59
60pairDevice(deviceId: string): Promise&lt;void&gt;
61
62Pairs a Bluetooth device. This API uses a promise to return the result.
63
64**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
65
66**System capability**: SystemCapability.Communication.Bluetooth.Core
67
68**Parameters**
69
70| Name     | Type    | Mandatory  | Description                                 |
71| -------- | ------ | ---- | ----------------------------------- |
72| deviceId | string | Yes   | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.|
73
74**Return value**
75
76| Type                 | Description           |
77| ------------------- | ------------- |
78| Promise&lt;void&gt; | Promise used to return the result.|
79
80**Error codes**
81
82For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
83
84| ID| Error Message|
85| -------- | ---------------------------- |
86|2900001 | Service stopped.                         |
87|2900003 | Bluetooth switch is off.                 |
88|2900099 | Operation failed.                        |
89
90**Example**
91
92```js
93try {
94    // The address can be scanned.
95    connection.pairDevice('XX:XX:XX:XX:XX:XX');
96} catch (err) {
97    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
98}
99```
100
101
102## connection.pairCredibleDevice
103
104pairCredibleDevice(deviceId: string, transport: BluetoothTransport, callback: AsyncCallback&lt;void&gt;): void
105
106Pairs a trusted device whose address is obtained in a non-Bluetooth scan mode (such as using NFC). This API uses an asynchronous callback to return the result.
107
108**System API**: This is a system API.
109
110**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
111
112**System capability**: SystemCapability.Communication.Bluetooth.Core
113
114**Parameters**
115
116| Name     | Type    | Mandatory  | Description                                 |
117| -------- | ------ | ---- | ----------------------------------- |
118| deviceId | string | Yes   | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.|
119| transport | [BluetoothTransport](#bluetoothtransport) | Yes   | Device type, for example, a classic Bluetooth device or a Bluetooth low energy (BLE) device.|
120| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.  |
121
122**Error codes**
123
124For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
125
126| ID| Error Message|
127| -------- | ---------------------------- |
128|2900001 | Service stopped.                         |
129|2900003 | Bluetooth switch is off.                 |
130|2900099 | Operation failed.                        |
131
132**Example**
133
134```js
135try {
136    connection.pairCredibleDevice('68:13:24:79:4C:8C', connection.BluetoothTransport
137        .TRANSPORT_BR_EDR, (err: BusinessError) => {
138        if (err) {
139            console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
140            return;
141        }
142        console.info('pairCredibleDevice, err: ' + JSON.stringify(err));
143    });
144} catch (err) {
145    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
146}
147```
148
149
150## connection.pairCredibleDevice
151
152pairCredibleDevice(deviceId: string, transport: BluetoothTransport): Promise&lt;void&gt;
153
154Pairs a trusted device whose address is obtained in a non-Bluetooth scan mode (such as using NFC). This API uses a promise to return the result.
155
156**System API**: This is a system API.
157
158**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
159
160**System capability**: SystemCapability.Communication.Bluetooth.Core
161
162**Parameters**
163
164| Name     | Type    | Mandatory  | Description                                 |
165| -------- | ------ | ---- | ----------------------------------- |
166| deviceId | string | Yes   | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.|
167| transport | [BluetoothTransport](#bluetoothtransport) | Yes   | Device type, for example, a classic Bluetooth device or a BLE device.|
168
169**Return value**
170
171| Type                                             | Description               |
172| ------------------------------------------------- | ------------------- |
173| Promise&lt;void&gt; | Promise used to return the result.|
174
175**Error codes**
176
177For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
178
179| ID| Error Message|
180| -------- | ---------------------------- |
181|2900001 | Service stopped.                         |
182|2900003 | Bluetooth switch is off.                 |
183|2900099 | Operation failed.                        |
184
185**Example**
186
187```js
188try {
189    connection.pairCredibleDevice('68:13:24:79:4C:8C', 0).then(() => {
190        console.info('PairCredibleDevice');
191    }, (err: BusinessError) => {
192        console.error('PairCredibleDevice:errCode' + err.code + ', errMessage: ' + err.message);
193    });
194} catch (err) {
195    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
196}
197```
198
199
200## connection.cancelPairedDevice<a name="cancelPairedDevice"></a>
201
202cancelPairedDevice(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
203
204Cancels a paired device.
205
206**System API**: This is a system API.
207
208**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
209
210**System capability**: SystemCapability.Communication.Bluetooth.Core
211
212**Parameters**
213
214| Name     | Type    | Mandatory  | Description                                   |
215| -------- | ------ | ---- | ------------------------------------- |
216| deviceId | string | Yes   | Address of the device to cancel, for example, XX:XX:XX:XX:XX:XX.|
217| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.  |
218
219**Error codes**
220
221For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
222
223| ID| Error Message|
224| -------- | ---------------------------- |
225|2900001 | Service stopped.                         |
226|2900003 | Bluetooth switch is off.                 |
227|2900099 | Operation failed.                        |
228
229**Example**
230
231```js
232try {
233    connection.cancelPairedDevice('XX:XX:XX:XX:XX:XX');
234} catch (err) {
235    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
236}
237```
238
239
240## connection.cancelPairedDevice<a name="cancelPairedDevice"></a>
241
242cancelPairedDevice(deviceId: string): Promise&lt;void&gt;
243
244Cancels a paired device. This API uses a promise to return the result.
245
246**System API**: This is a system API.
247
248**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
249
250**System capability**: SystemCapability.Communication.Bluetooth.Core
251
252**Parameters**
253
254| Name     | Type    | Mandatory  | Description                                   |
255| -------- | ------ | ---- | ------------------------------------- |
256| deviceId | string | Yes   | Address of the device to cancel, for example, XX:XX:XX:XX:XX:XX.|
257
258**Return value**
259
260| Type                 | Description           |
261| ------------------- | ------------- |
262| Promise&lt;void&gt; | Promise used to return the result.|
263
264**Error codes**
265
266For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
267
268| ID| Error Message|
269| -------- | ---------------------------- |
270|2900001 | Service stopped.                         |
271|2900003 | Bluetooth switch is off.                 |
272|2900099 | Operation failed.                        |
273
274**Example**
275
276```js
277try {
278    connection.cancelPairedDevice('XX:XX:XX:XX:XX:XX');
279} catch (err) {
280    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
281}
282```
283
284
285## connection.cancelPairingDevice<a name="cancelPairingDevice"></a>
286
287cancelPairingDevice(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
288
289Cancels the pairing of a device. This API uses an asynchronous callback to return the result.
290
291**System API**: This is a system API.
292
293**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
294
295**System capability**: SystemCapability.Communication.Bluetooth.Core
296
297**Parameters**
298
299| Name     | Type    | Mandatory  | Description                                   |
300| -------- | ------ | ---- | ------------------------------------- |
301| deviceId | string | Yes   | Address of the device to cancel, for example, XX:XX:XX:XX:XX:XX.|
302| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.  |
303
304**Error codes**
305
306For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
307
308| ID| Error Message|
309| -------- | ---------------------------- |
310|2900001 | Service stopped.                         |
311|2900003 | Bluetooth switch is off.                 |
312|2900099 | Operation failed.                        |
313
314**Example**
315
316```js
317try {
318    connection.cancelPairingDevice('XX:XX:XX:XX:XX:XX');
319} catch (err) {
320    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
321}
322```
323
324
325## connection.cancelPairingDevice<a name="cancelPairingDevice"></a>
326
327cancelPairingDevice(deviceId: string): Promise&lt;void&gt;
328
329Cancels the pairing of a device. This API uses a promise to return the result.
330
331**System API**: This is a system API.
332
333**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
334
335**System capability**: SystemCapability.Communication.Bluetooth.Core
336
337**Parameters**
338
339| Name     | Type    | Mandatory  | Description                                   |
340| -------- | ------ | ---- | ------------------------------------- |
341| deviceId | string | Yes   | Address of the device to cancel, for example, XX:XX:XX:XX:XX:XX.|
342
343**Return value**
344
345| Type                 | Description           |
346| ------------------- | ------------- |
347| Promise&lt;void&gt; | Promise used to return the result.|
348
349**Error codes**
350
351For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
352
353| ID| Error Message|
354| -------- | ---------------------------- |
355|2900001 | Service stopped.                         |
356|2900003 | Bluetooth switch is off.                 |
357|2900099 | Operation failed.                        |
358
359**Example**
360
361```js
362try {
363    connection.cancelPairingDevice('XX:XX:XX:XX:XX:XX');
364} catch (err) {
365    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
366}
367```
368
369
370## connection.getRemoteDeviceName<a name="getRemoteDeviceName"></a>
371
372getRemoteDeviceName(deviceId: string): string
373
374Obtains the name of a remote Bluetooth device.
375
376**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
377
378**System capability**: SystemCapability.Communication.Bluetooth.Core
379
380**Parameters**
381
382| Name     | Type    | Mandatory  | Description                               |
383| -------- | ------ | ---- | --------------------------------- |
384| deviceId | string | Yes   | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
385
386**Return value**
387
388| Type    | Description           |
389| ------ | ------------- |
390| string | Device name (a string) obtained.|
391
392**Error codes**
393
394For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
395
396| ID| Error Message|
397| -------- | ---------------------------- |
398|2900001 | Service stopped.                         |
399|2900003 | Bluetooth switch is off.                 |
400|2900099 | Operation failed.                        |
401
402**Example**
403
404```js
405try {
406    let remoteDeviceName: string = connection.getRemoteDeviceName('XX:XX:XX:XX:XX:XX');
407} catch (err) {
408    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
409}
410```
411
412
413## connection.getRemoteDeviceClass<a name="getRemoteDeviceClass"></a>
414
415getRemoteDeviceClass(deviceId: string): DeviceClass
416
417Obtains the class of a remote Bluetooth device.
418
419**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
420
421**System capability**: SystemCapability.Communication.Bluetooth.Core
422
423**Parameters**
424
425| Name     | Type    | Mandatory  | Description                               |
426| -------- | ------ | ---- | --------------------------------- |
427| deviceId | string | Yes   | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
428
429**Return value**
430
431| Type                         | Description      |
432| --------------------------- | -------- |
433| [DeviceClass](#deviceclass) | Class of the remote device obtained.|
434
435**Error codes**
436
437For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
438
439| ID| Error Message|
440| -------- | ---------------------------- |
441|2900001 | Service stopped.                         |
442|2900003 | Bluetooth switch is off.                 |
443|2900099 | Operation failed.                        |
444
445**Example**
446
447```js
448try {
449    let remoteDeviceClass: connection.DeviceClass = connection.getRemoteDeviceClass('XX:XX:XX:XX:XX:XX');
450} catch (err) {
451    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
452}
453```
454
455
456## connection.getLocalName<a name="getLocalName"></a>
457
458getLocalName(): string
459
460Obtains the name of the local Bluetooth device.
461
462**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
463
464**System capability**: SystemCapability.Communication.Bluetooth.Core
465
466**Return value**
467
468| Type    | Description       |
469| ------ | --------- |
470| string | Name of the local Bluetooth device obtained.|
471
472**Error codes**
473
474For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
475
476| ID| Error Message|
477| -------- | ---------------------------- |
478|2900001 | Service stopped.                         |
479|2900099 | Operation failed.                        |
480
481**Example**
482
483```js
484try {
485    let localName: string = connection.getLocalName();
486} catch (err) {
487    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
488}
489```
490
491
492## connection.getPairedDevices<a name="getPairedDevices"></a>
493
494getPairedDevices(): Array&lt;string&gt;
495
496Obtains the paired devices.
497
498**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
499
500**System capability**: SystemCapability.Communication.Bluetooth.Core
501
502**Return value**
503
504| Type                 | Description           |
505| ------------------- | ------------- |
506| Array&lt;string&gt; | Addresses of the paired Bluetooth devices obtained. |
507
508**Error codes**
509
510For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
511
512| ID| Error Message|
513| -------- | ---------------------------- |
514|2900001 | Service stopped.                         |
515|2900003 | Bluetooth switch is off.                 |
516|2900099 | Operation failed.                        |
517
518**Example**
519
520```js
521try {
522    let devices: Array<string> = connection.getPairedDevices();
523} catch (err) {
524    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
525}
526```
527
528
529## connection.getProfileConnectionState<a name="getProfileConnectionState"></a>
530
531getProfileConnectionState(profileId?: ProfileId): ProfileConnectionState
532
533Obtains the connection state of a Bluetooth profile. The **ProfileId** parameter is optional. If **ProfileId** is specified, the connection state of the specified profile is returned. If no **ProfileId** is specified, [STATE_CONNECTED](js-apis-bluetooth-constant.md#profileconnectionstate) is returned by any connected profile. If no profile is connected, [STATE_DISCONNECTED](js-apis-bluetooth-constant.md#profileconnectionstate) is returned.
534
535**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
536
537**System capability**: SystemCapability.Communication.Bluetooth.Core
538
539**Parameters**
540
541| Name      | Type       | Mandatory  | Description                                   |
542| --------- | --------- | ---- | ------------------------------------- |
543| ProfileId | [profileId](js-apis-bluetooth-constant.md#profileid) | No   | ID of the target profile, for example, **PROFILE_A2DP_SOURCE**.|
544
545**Return value**
546
547| Type                                             | Description               |
548| ------------------------------------------------- | ------------------- |
549| [ProfileConnectionState](js-apis-bluetooth-constant.md#profileconnectionstate) | Profile connection state obtained.|
550
551**Error codes**
552
553For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
554
555| ID| Error Message|
556| -------- | ---------------------------- |
557|2900001 | Service stopped.                         |
558|2900003 | Bluetooth switch is off.                 |
559|2900004 | Profile is not supported.                |
560|2900099 | Operation failed.                        |
561
562**Example**
563
564```js
565import constant from '@ohos.bluetooth.constant';
566try {
567    let result: connection.ProfileConnectionState = connection.getProfileConnectionState(constant.ProfileId.PROFILE_A2DP_SOURCE);
568} catch (err) {
569    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
570}
571```
572
573
574## connection.setDevicePairingConfirmation<a name="setDevicePairingConfirmation"></a>
575
576setDevicePairingConfirmation(deviceId: string, accept: boolean): void
577
578Sets the device pairing confirmation.
579
580**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
581
582**System capability**: SystemCapability.Communication.Bluetooth.Core
583
584**Parameters**
585
586| Name   | Type     | Mandatory  | Description                              |
587| ------   | ------- | ---- | -------------------------------- |
588| deviceId | string  | Yes   | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
589| accept   | boolean | Yes   | Whether to accept the pairing request. The value **true** means to accept the pairing request, and the value **false** means the opposite.       |
590
591**Error codes**
592
593For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
594
595| ID| Error Message|
596| -------- | ---------------------------- |
597|2900001 | Service stopped.                         |
598|2900003 | Bluetooth switch is off.                 |
599|2900099 | Operation failed.                        |
600
601**Example**
602
603```js
604// Subscribe to the pinRequired event and configure the pairing confirmation after receiving a pairing request from the remote device.
605function onReceivePinRequiredEvent(data: connection.PinRequiredParam) { // data is the input parameter for the pairing request.
606    console.info('pin required  = '+ JSON.stringify(data));
607    connection.setDevicePairingConfirmation(data.deviceId, true);
608}
609try {
610    connection.on('pinRequired', onReceivePinRequiredEvent);
611} catch (err) {
612    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
613}
614```
615
616
617## connection.setDevicePinCode<a name="setDevicePinCode"></a>
618
619setDevicePinCode(deviceId: string, code: string, callback: AsyncCallback&lt;void&gt;): void
620
621Sets the PIN for the device when [PinType](#pintype) is **PIN_TYPE_ENTER_PIN_CODE** or **PIN_TYPE_PIN_16_DIGITS**. This API uses an asynchronous callback to return the result.
622
623**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
624
625**System capability**: SystemCapability.Communication.Bluetooth.Core
626
627**Parameters**
628
629| Name   | Type     | Mandatory  | Description                              |
630| ------ | ------- | ---- | -------------------------------- |
631| deviceId | string  | Yes   | MAC address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
632| code   | string  | Yes   | PIN to set.       |
633| callback   | AsyncCallback&lt;void&gt;  | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.       |
634
635**Error codes**
636
637For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
638
639| ID| Error Message|
640| -------- | ---------------------------- |
641|2900001 | Service stopped.                         |
642|2900003 | Bluetooth switch is off.                 |
643|2900099 | Operation failed.                        |
644
645**Example**
646
647```js
648//callback
649try {
650    connection.setDevicePinCode('11:22:33:44:55:66', '12345', (err: BusinessError) => {
651        console.info('setDevicePinCode,device name err:' + JSON.stringify(err));
652    });
653} catch (err) {
654    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
655}
656```
657
658
659## connection.setDevicePinCode<a name="setDevicePinCode-1"></a>
660
661setDevicePinCode(deviceId: string, code: string): Promise&lt;void&gt;
662
663Sets the PIN for the device when [PinType](#pintype) is **PIN_TYPE_ENTER_PIN_CODE** or **PIN_TYPE_PIN_16_DIGITS**. This API uses a promise to return the result.
664
665**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
666
667**System capability**: SystemCapability.Communication.Bluetooth.Core
668
669**Parameters**
670
671| Name   | Type     | Mandatory  | Description                              |
672| ------ | ------- | ---- | -------------------------------- |
673| deviceId | string  | Yes   | MAC address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
674| code   | string  | Yes   | PIN to set.       |
675
676**Return value**
677
678| Type                 | Description           |
679| ------------------- | ------------- |
680| Promise&lt;void&gt; | Promise used to return the result.|
681
682**Error codes**
683
684For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
685
686| ID| Error Message|
687| -------- | ---------------------------- |
688|2900001 | Service stopped.                         |
689|2900003 | Bluetooth switch is off.                 |
690|2900099 | Operation failed.                        |
691
692**Example**
693
694```js
695//promise
696try {
697    connection.setDevicePinCode('11:22:33:44:55:66', '12345').then(() => {
698        console.info('setDevicePinCode');
699    }, (error: BusinessError) => {
700        console.info('setDevicePinCode: errCode:' + error.code + ',errMessage' + error.message);
701    })
702
703} catch (err) {
704    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
705}
706```
707
708
709## connection.setLocalName<a name="setLocalName"></a>
710
711setLocalName(name: string): void
712
713Sets the name of the local Bluetooth device.
714
715**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
716
717**System capability**: SystemCapability.Communication.Bluetooth.Core
718
719**Parameters**
720
721| Name | Type    | Mandatory  | Description                   |
722| ---- | ------ | ---- | --------------------- |
723| name | string | Yes   | Bluetooth device name to set. It cannot exceed 248 bytes.|
724
725**Error codes**
726
727For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
728
729| ID| Error Message|
730| -------- | ---------------------------- |
731|2900001 | Service stopped.                         |
732|2900003 | Bluetooth switch is off.                 |
733|2900099 | Operation failed.                        |
734
735**Example**
736
737```js
738try {
739    connection.setLocalName('device_name');
740} catch (err) {
741    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
742}
743```
744
745
746## connection.setBluetoothScanMode<a name="setBluetoothScanMode"></a>
747
748setBluetoothScanMode(mode: ScanMode, duration: number): void
749
750Sets the Bluetooth scan mode so that the device can be discovered by a remote device.
751
752**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
753
754**System capability**: SystemCapability.Communication.Bluetooth.Core
755
756**Parameters**
757
758| Name     | Type                   | Mandatory  | Description                          |
759| -------- | --------------------- | ---- | ---------------------------- |
760| mode     | [ScanMode](#scanmode) | Yes   | Bluetooth scan mode to set.                     |
761| duration | number                | Yes   | Duration (in ms) in which the device can be discovered. The value **0** indicates unlimited time.|
762
763**Error codes**
764
765For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
766
767| ID| Error Message|
768| -------- | ---------------------------- |
769|2900001 | Service stopped.                         |
770|2900003 | Bluetooth switch is off.                 |
771|2900099 | Operation failed.                        |
772
773**Example**
774
775```js
776try {
777    // The device can be discovered and connected only when the discoverable and connectable mode is used.
778    connection.setBluetoothScanMode(connection.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 100);
779} catch (err) {
780    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
781}
782```
783
784
785## connection.getBluetoothScanMode<a name="getBluetoothScanMode"></a>
786
787getBluetoothScanMode(): ScanMode
788
789Obtains the Bluetooth scan mode.
790
791**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
792
793**System capability**: SystemCapability.Communication.Bluetooth.Core
794
795**Return value**
796
797| Type                   | Description     |
798| --------------------- | ------- |
799| [ScanMode](#scanmode) | Bluetooth scan mode obtained. |
800
801**Error codes**
802
803For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
804
805| ID| Error Message|
806| -------- | ---------------------------- |
807|2900001 | Service stopped.                         |
808|2900003 | Bluetooth switch is off.                 |
809|2900099 | Operation failed.                        |
810
811**Example**
812
813```js
814try {
815    let scanMode: connection.ScanMode = connection.getBluetoothScanMode();
816} catch (err) {
817    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
818}
819```
820
821
822## connection.startBluetoothDiscovery<a name="startBluetoothDiscovery"></a>
823
824startBluetoothDiscovery(): void
825
826Starts discovery of Bluetooth devices.
827
828**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
829
830**System capability**: SystemCapability.Communication.Bluetooth.Core
831
832**Error codes**
833
834For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
835
836| ID| Error Message|
837| -------- | ---------------------------- |
838|2900001 | Service stopped.                         |
839|2900003 | Bluetooth switch is off.                 |
840|2900099 | Operation failed.                        |
841
842**Example**
843
844```js
845function onReceiveEvent(data: Array<string>) {
846    console.log('data length' + data.length);
847}
848try {
849    connection.on('bluetoothDeviceFind', onReceiveEvent);
850    connection.startBluetoothDiscovery();
851} catch (err) {
852    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
853}
854```
855
856
857## connection.stopBluetoothDiscovery<a name="stopBluetoothDiscovery"></a>
858
859stopBluetoothDiscovery(): void
860
861Stops discovery of Bluetooth devices.
862
863**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
864
865**System capability**: SystemCapability.Communication.Bluetooth.Core
866
867**Error codes**
868
869For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
870
871| ID| Error Message|
872| -------- | ---------------------------- |
873|2900001 | Service stopped.                         |
874|2900003 | Bluetooth switch is off.                 |
875|2900099 | Operation failed.                        |
876
877**Example**
878
879```js
880try {
881    connection.stopBluetoothDiscovery();
882} catch (err) {
883    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
884}
885```
886
887
888## connection.getLocalProfileUuids<a name="getLocalProfileUuids"></a>
889
890getLocalProfileUuids(callback: AsyncCallback&lt;Array&lt;ProfileUuids&gt;&gt;): void
891
892Obtains the profile UUIDs of the local device. This API uses an asynchronous callback to return the result.
893
894**System API**: This is a system API.
895
896**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
897
898**System capability**: SystemCapability.Communication.Bluetooth.Core
899
900**Parameters**
901
902| Name     | Type    | Mandatory  | Description                                 |
903| -------- | ------ | ---- | ----------------------------------- |
904| callback | AsyncCallback&lt;Array&lt;[ProfileUuids](js-apis-bluetooth-constant.md#profileuuids)&gt;&gt; | Yes   | Callback invoked to return the profile UUIDs obtained. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
905
906**Error codes**
907
908For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
909
910| ID| Error Message|
911| -------- | ---------------------------- |
912|2900001 | Service stopped.                         |
913|2900003 | Bluetooth switch is off.                 |
914|2900099 | Operation failed.                        |
915
916**Example**
917
918```js
919try {
920    connection.getLocalProfileUuids('XX:XX:XX:XX:XX:XX', (err: BusinessError, data: Array<connection.ProfileUuids>) => {
921        console.info('getLocalProfileUuids, err: ' + JSON.stringify(err) + ', data: ' + JSON.stringify(data));
922    });
923} catch (err) {
924    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
925}
926```
927
928
929## connection.getLocalProfileUuids<a name="getLocalProfileUuids"></a>
930
931getLocalProfileUuids(): Promise&lt;Array&lt;ProfileUuids&gt;&gt;
932
933Obtains the profile UUIDs of the local device. This API uses a promise to return the result.
934
935**System API**: This is a system API.
936
937**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
938
939**System capability**: SystemCapability.Communication.Bluetooth.Core
940
941**Return value**
942
943| Type                 | Description           |
944| ------------------- | ------------- |
945|   Promise&lt;Array&lt;[ProfileUuids](js-apis-bluetooth-constant.md#profileuuids)&gt;&gt; | Promise used to return the profile UUIDs obtained.|
946
947**Error codes**
948
949For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
950
951| ID| Error Message|
952| -------- | ---------------------------- |
953|2900001 | Service stopped.                         |
954|2900003 | Bluetooth switch is off.                 |
955|2900099 | Operation failed.                        |
956
957**Example**
958
959```js
960try {
961    connection.getLocalProfileUuids('XX:XX:XX:XX:XX:XX').then(() => {
962        console.info('getLocalProfileUuids');
963    }, (err: BusinessError) => {
964        console.error('getLocalProfileUuids: errCode' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
965    });
966} catch (err) {
967    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
968}
969```
970
971
972## connection.getRemoteProfileUuids<a name="getRemoteProfileUuids"></a>
973
974getRemoteProfileUuids(deviceId: string, callback: AsyncCallback&lt;Array&lt;ProfileUuids&gt;&gt;): void
975
976Obtains the profile UUIDs of a remote Bluetooth device. This API uses an asynchronous callback to return the result.
977
978**System API**: This is a system API.
979
980**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
981
982**System capability**: SystemCapability.Communication.Bluetooth.Core
983
984**Parameters**
985
986| Name     | Type    | Mandatory  | Description                                 |
987| -------- | ------ | ---- | ----------------------------------- |
988| deviceId | string | Yes   | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.|
989| callback | AsyncCallback&lt;Array&lt;[ProfileUuids](js-apis-bluetooth-constant.md#profileuuids)&gt;&gt; | Yes   | Callback invoked to return the profile UUIDs obtained. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
990
991**Error codes**
992
993For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
994
995| ID| Error Message|
996| -------- | ---------------------------- |
997|2900001 | Service stopped.                         |
998|2900003 | Bluetooth switch is off.                 |
999|2900099 | Operation failed.                        |
1000
1001**Example**
1002
1003```js
1004try {
1005    connection.getRemoteProfileUuids('XX:XX:XX:XX:XX:XX', (err: BusinessError, data: Array<connection.ProfileUuids>) => {
1006        console.info('getRemoteProfileUuids, err: ' + JSON.stringify(err) + ', data: ' + JSON.stringify(data));
1007    });
1008} catch (err) {
1009    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
1010}
1011
1012```
1013
1014
1015## connection.getRemoteProfileUuids<a name="getRemoteProfileUuids"></a>
1016
1017getRemoteProfileUuids(deviceId: string): Promise&lt;Array&lt;ProfileUuids&gt;&gt;
1018
1019Obtains the profile UUIDs of a remote Bluetooth device. This API uses a promise to return the result.
1020
1021**System API**: This is a system API.
1022
1023**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
1024
1025**System capability**: SystemCapability.Communication.Bluetooth.Core
1026
1027**Parameters**
1028
1029| Name     | Type    | Mandatory  | Description                                 |
1030| -------- | ------ | ---- | ----------------------------------- |
1031| deviceId | string | Yes   | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX.|
1032
1033**Return value**
1034
1035| Type                 | Description           |
1036| ------------------- | ------------- |
1037|   Promise&lt;Array&lt;[ProfileUuids](js-apis-bluetooth-constant.md#profileuuids)&gt;&gt; | Promise used to return the profile UUIDs obtained.|
1038
1039**Error codes**
1040
1041For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1042
1043| ID| Error Message|
1044| -------- | ---------------------------- |
1045|2900001 | Service stopped.                         |
1046|2900003 | Bluetooth switch is off.                 |
1047|2900099 | Operation failed.                        |
1048
1049**Example**
1050
1051```js
1052try {
1053    connection.getRemoteProfileUuids('XX:XX:XX:XX:XX:XX').then(() => {
1054        console.info('getRemoteProfileUuids');
1055    }, (err: BusinessError) => {
1056        console.error('getRemoteProfileUuids: errCode' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
1057    });
1058} catch (err) {
1059    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
1060}
1061```
1062
1063
1064## connection.on('bluetoothDeviceFind')
1065
1066on(type: 'bluetoothDeviceFind', callback: Callback&lt;Array&lt;string&gt;&gt;): void
1067
1068Subscribes to the discovery of a Bluetooth device.
1069
1070**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
1071
1072**System capability**: SystemCapability.Communication.Bluetooth.Core
1073
1074**Parameters**
1075
1076| Name     | Type                                 | Mandatory  | Description                                    |
1077| -------- | ----------------------------------- | ---- | -------------------------------------- |
1078| type     | string                              | Yes   | Event type. The value is **bluetoothDeviceFind**, which indicates an event of discovering a Bluetooth device.|
1079| callback | Callback&lt;Array&lt;string&gt;&gt; | Yes   | Callback invoked to return the discovered devices. You need to implement this callback.   |
1080
1081**Error codes**
1082
1083For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1084
1085| ID| Error Message|
1086| -------- | ---------------------------- |
1087|2900099 | Operation failed.                        |
1088
1089**Example**
1090
1091```js
1092function onReceiveEvent(data: Array<string>) { // data is an array of Bluetooth device addresses.
1093    console.info('bluetooth device find = '+ JSON.stringify(data));
1094}
1095try {
1096    connection.on('bluetoothDeviceFind', onReceiveEvent);
1097} catch (err) {
1098    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
1099}
1100```
1101
1102
1103## connection.off('bluetoothDeviceFind')
1104
1105off(type: 'bluetoothDeviceFind', callback?: Callback&lt;Array&lt;string&gt;&gt;): void
1106
1107Unsubscribes from the discovery of a Bluetooth device.
1108
1109**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
1110
1111**System capability**: SystemCapability.Communication.Bluetooth.Core
1112
1113**Parameters**
1114
1115| Name     | Type                                 | Mandatory  | Description                                      |
1116| -------- | ----------------------------------- | ---- | ---------------------------------------- |
1117| type     | string                              | Yes   | Event type. The value is **bluetoothDeviceFind**, which indicates an event of discovering a Bluetooth device.  |
1118| callback | Callback&lt;Array&lt;string&gt;&gt; | No   | Callback for the **bluetoothDeviceFind** event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
1119
1120**Error codes**
1121
1122For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1123
1124| ID| Error Message|
1125| -------- | ---------------------------- |
1126|2900099 | Operation failed.                        |
1127
1128**Example**
1129
1130```js
1131function onReceiveEvent(data: Array<string>) {
1132    console.info('bluetooth device find = '+ JSON.stringify(data));
1133}
1134try {
1135    connection.on('bluetoothDeviceFind', onReceiveEvent);
1136    connection.off('bluetoothDeviceFind', onReceiveEvent);
1137} catch (err) {
1138    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
1139}
1140```
1141
1142
1143## connection.on('bondStateChange')
1144
1145on(type: 'bondStateChange', callback: Callback&lt;BondStateParam&gt;): void
1146
1147Subscribes to Bluetooth pairing state changes.
1148
1149**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
1150
1151**System capability**: SystemCapability.Communication.Bluetooth.Core
1152
1153**Parameters**
1154
1155| Name     | Type                                      | Mandatory  | Description                                  |
1156| -------- | ---------------------------------------- | ---- | ------------------------------------ |
1157| type     | string                                   | Yes   | Event type. The value is **bondStateChange**, which indicates a Bluetooth pairing state change event.|
1158| callback | Callback&lt;[BondStateParam](#BondStateParam)&gt; | Yes   | Callback invoked to return the pairing state. You need to implement this callback.   |
1159
1160**Error codes**
1161
1162For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1163
1164| ID| Error Message|
1165| -------- | ---------------------------- |
1166|2900099 | Operation failed.                        |
1167
1168**Example**
1169
1170```js
1171function onReceiveEvent(data: connection.BondStateParam) { // data, as the input parameter of the callback, indicates the pairing state.
1172    console.info('pair state = '+ JSON.stringify(data));
1173}
1174try {
1175    connection.on('bondStateChange', onReceiveEvent);
1176} catch (err) {
1177    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
1178}
1179```
1180
1181
1182## connection.off('bondStateChange')
1183
1184off(type: 'bondStateChange', callback?: Callback&lt;BondStateParam&gt;): void
1185
1186Unsubscribes from Bluetooth pairing state changes.
1187
1188**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
1189
1190**System capability**: SystemCapability.Communication.Bluetooth.Core
1191
1192**Parameters**
1193
1194| Name     | Type                                      | Mandatory  | Description                                      |
1195| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1196| type     | string                                   | Yes   | Event type. The value is **bondStateChange**, which indicates a Bluetooth pairing state change event.    |
1197| callback | Callback&lt;[BondStateParam](#BondStateParam)&gt; | No   | Callback for the change of the Bluetooth pairing state. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
1198
1199**Error codes**
1200
1201For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1202
1203| ID| Error Message|
1204| -------- | ---------------------------- |
1205|2900099 | Operation failed.                        |
1206
1207**Example**
1208
1209```js
1210function onReceiveEvent(data: connection.BondStateParam) {
1211    console.info('bond state = '+ JSON.stringify(data));
1212}
1213try {
1214    connection.on('bondStateChange', onReceiveEvent);
1215    connection.off('bondStateChange', onReceiveEvent);
1216} catch (err) {
1217    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
1218}
1219```
1220
1221
1222## connection.on('pinRequired')
1223
1224on(type: 'pinRequired', callback: Callback&lt;PinRequiredParam&gt;): void
1225
1226Subscribes to the pairing request events of the remote Bluetooth device.
1227
1228**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
1229
1230**System capability**: SystemCapability.Communication.Bluetooth.Core
1231
1232**Parameters**
1233
1234| Name     | Type                                      | Mandatory  | Description                              |
1235| -------- | ---------------------------------------- | ---- | -------------------------------- |
1236| type     | string                                   | Yes   | Event type. The value **pinRequired** indicates a pairing request event.    |
1237| callback | Callback&lt;[PinRequiredParam](#pinrequiredparam)&gt; | Yes   | Callback invoked to return the pairing request. You need to implement this callback.|
1238
1239**Error codes**
1240
1241For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1242
1243| ID| Error Message|
1244| -------- | ---------------------------- |
1245|2900099 | Operation failed.                        |
1246
1247**Example**
1248
1249```js
1250function onReceiveEvent(data: connection.PinRequiredParam) { // data is the pairing request parameter.
1251    console.info('pin required = '+ JSON.stringify(data));
1252}
1253try {
1254    connection.on('pinRequired', onReceiveEvent);
1255} catch (err) {
1256    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
1257}
1258```
1259
1260
1261## connection.off('pinRequired')
1262
1263off(type: 'pinRequired', callback?: Callback&lt;PinRequiredParam&gt;): void
1264
1265Unsubscribes from the pairing request events of the remote Bluetooth device.
1266
1267**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
1268
1269**System capability**: SystemCapability.Communication.Bluetooth.Core
1270
1271**Parameters**
1272
1273| Name     | Type                                      | Mandatory  | Description                                      |
1274| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1275| type     | string                                   | Yes   | Event type. The value **pinRequired** indicates a pairing request event.            |
1276| callback | Callback&lt;[PinRequiredParam](#pinrequiredparam)&gt; | No   | Callback for the Bluetooth pairing request event. The input parameter is the pairing request parameter. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
1277
1278**Error codes**
1279
1280For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
1281
1282| ID| Error Message|
1283| -------- | ---------------------------- |
1284|2900099 | Operation failed.                        |
1285
1286**Example**
1287
1288```js
1289function onReceiveEvent(data: connection.PinRequiredParam) {
1290    console.info('pin required = '+ JSON.stringify(data));
1291}
1292try {
1293    connection.on('pinRequired', onReceiveEvent);
1294    connection.off('pinRequired', onReceiveEvent);
1295} catch (err) {
1296    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
1297}
1298```
1299
1300
1301## BondStateParam<a name="BondStateParam"></a>
1302
1303Represents the pairing state parameters.
1304
1305**System capability**: SystemCapability.Communication.Bluetooth.Core
1306
1307| Name      | Type  | Readable  | Writable  | Description         |
1308| -------- | ------ | ---- | ---- | ----------- |
1309| deviceId | string      | Yes   | No   | ID of the device to pair.|
1310| state    | BondState   | Yes   | No   | State of the device.|
1311
1312
1313## PinRequiredParam<a name="PinRequiredParam"></a>
1314
1315Represents the pairing request parameters.
1316
1317**System capability**: SystemCapability.Communication.Bluetooth.Core
1318
1319| Name      | Type  | Readable  | Writable  | Description         |
1320| -------- | ------ | ---- | ---- | ----------- |
1321| deviceId | string | Yes   | No   | ID of the device to pair.|
1322| pinCode  | string | Yes   | No   | Key for the device pairing.  |
1323| pinType | [PinType](#pintype) | Yes   | No   | Type of the device to pair.<br>This is a system API.  |
1324
1325
1326## DeviceClass<a name="DeviceClass"></a>
1327
1328Represents the class of a Bluetooth device.
1329
1330**System capability**: SystemCapability.Communication.Bluetooth.Core
1331
1332| Name             | Type                               | Readable  | Writable  | Description              |
1333| --------------- | ----------------------------------- | ---- | ---- | ---------------- |
1334| majorClass      | [MajorClass](js-apis-bluetooth-constant.md#majorclass)           | Yes   | No   | Major class of the Bluetooth device.  |
1335| majorMinorClass | [MajorMinorClass](js-apis-bluetooth-constant.md#majorminorclass) | Yes   | No   | Major and minor classes of the Bluetooth device.|
1336| classOfDevice   | number                              | Yes   | No   | Class of the device.         |
1337
1338
1339## BluetoothTransport<a name="BluetoothTransport"></a>
1340
1341Enumerates the device types. The default device type is **TRANSPORT_BR_EDR**.
1342
1343**System capability**: SystemCapability.Communication.Bluetooth.Core
1344
1345| Name                              | Value   | Description             |
1346| -------------------------------- | ------ | --------------- |
1347| TRANSPORT_BR_EDR   | 0 | Classic Bluetooth (BR/EDR) device.|
1348| TRANSPORT_LE  | 1 | BLE device. |
1349
1350
1351## ScanMode<a name="ScanMode"></a>
1352
1353Enumerates the scan modes.
1354
1355**System capability**: SystemCapability.Communication.Bluetooth.Core
1356
1357| Name                                      | Value | Description             |
1358| ---------------------------------------- | ---- | --------------- |
1359| SCAN_MODE_NONE                           | 0    | No scan mode.        |
1360| SCAN_MODE_CONNECTABLE                    | 1    | Connectable mode.       |
1361| SCAN_MODE_GENERAL_DISCOVERABLE           | 2    | General discoverable mode.   |
1362| SCAN_MODE_LIMITED_DISCOVERABLE           | 3    | Limited discoverable mode.   |
1363| SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE | 4    | General connectable and discoverable mode.|
1364| SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE | 5    | Limited connectable and discoverable mode.|
1365
1366
1367## BondState<a name="BondState"></a>
1368
1369Enumerates the pairing states.
1370
1371**System capability**: SystemCapability.Communication.Bluetooth.Core
1372
1373| Name                | Value | Description    |
1374| ------------------ | ---- | ------ |
1375| BOND_STATE_INVALID | 0    | Invalid pairing.|
1376| BOND_STATE_BONDING | 1    | Pairing. |
1377| BOND_STATE_BONDED  | 2    | Paired.  |
1378
1379
1380## PinType<a name="PinType"></a>
1381
1382Enumerates the Bluetooth pairing types.
1383
1384**System API**: This is a system API.
1385
1386**System capability**: SystemCapability.Communication.Bluetooth.Core
1387
1388| Name                              | Value   | Description             |
1389| -------------------------------- | ------ | --------------- |
1390| PIN_TYPE_ENTER_PIN_CODE | 0 | The user needs to enter the PIN displayed on the peer device.<br>This is a system API.|
1391| PIN_TYPE_ENTER_PASSKEY  | 1 | The user needs to enter the PASSKEY displayed on the peer device.<br>This is a system API. |
1392| PIN_TYPE_CONFIRM_PASSKEY  | 2 | The user needs to confirm the PASSKEY displayed on the local device.<br>This is a system API. |
1393| PIN_TYPE_NO_PASSKEY_CONSENT  | 3 | There is no PASSKEY, and the user needs to accept or reject the pairing request.<br>This is a system API. |
1394| PIN_TYPE_NOTIFY_PASSKEY   | 4 | The user needs to enter the PASSKEY displayed on the local device on the peer device.<br>This is a system API. |
1395| PIN_TYPE_DISPLAY_PIN_CODE    | 5 | The user needs to enter the PIN displayed on the peer device for Bluetooth 2.0 devices.<br>This is a system API. |
1396| PIN_TYPE_OOB_CONSENT    | 6 | The user needs to accept or reject the out of band (OOB) pairing request.<br>This is a system API. |
1397| PIN_TYPE_PIN_16_DIGITS    | 7 | The user needs to enter the 16-digit PIN displayed on the peer device.<br>This is a system API. |
1398