1# @ohos.bluetooth.map (Bluetooth MAP Module) (System API)
2
3The **bluetooth.map** module provides APIs for exchanging messages between devices using the Bluetooth Message Access Profile (MAP).
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.bluetooth.map (Bluetooth MAP Module)](js-apis-bluetooth-map.md).
9
10
11## Modules to Import
12
13```js
14import { map } from '@kit.ConnectivityKit';
15```
16
17
18### disconnect
19
20disconnect(deviceId: string): void
21
22Disconnects the MAP service for a device.
23
24**System API**: This is a system API.
25
26**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
27
28**System capability**: SystemCapability.Communication.Bluetooth.Core
29
30**Parameters**
31
32| Name   | Type    | Mandatory  | Description     |
33| ------ | ------ | ---- | ------- |
34| deviceId | string | Yes   | Address of the remote device.|
35
36**Error codes**
37
38For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md).
39
40| ID| Error Message|
41| -------- | ---------------------------- |
42|201 | Permission denied.                 |
43|202 | Non-system applications are not allowed to use system APIs. |
44|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
45|801 | Capability not supported.          |
46|2900001 | Service stopped.                         |
47|2900003 | Bluetooth disabled.                 |
48|2900004 | Profile not supported.                |
49|2900099 | Operation failed.                        |
50
51**Example**
52
53```js
54import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
55try {
56    let mapMseProfile = map.createMapMseProfile();
57    mapMseProfile.disconnect('XX:XX:XX:XX:XX:XX');
58} catch (err) {
59    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
60}
61```
62
63### setMessageAccessAuthorization
64
65setMessageAccessAuthorization(deviceId: string, authorization: AccessAuthorization): Promise<void>
66
67Sets the message access authorization for a device. This API uses a promise to return the result.
68
69**System API**: This is a system API.
70
71**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
72
73**System capability**: SystemCapability.Communication.Bluetooth.Core
74
75**Parameters**
76
77| Name     | Type    | Mandatory  | Description                                 |
78| -------- | ------ | ---- | ----------------------------------- |
79| deviceId | string | Yes   | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
80| authorization | [AccessAuthorization](js-apis-bluetooth-constant-sys.md#AccessAuthorization) | Yes   | Message access authorization to set.|
81
82**Return value**
83
84| Type                                             | Description               |
85| ------------------------------------------------- | ------------------- |
86| Promise<void> | Promise used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
87
88**Error codes**
89
90For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md).
91
92| ID| Error Message|
93| -------- | ---------------------------- |
94|201 | Permission denied.                 |
95|202 | Non-system applications are not allowed to use system APIs. |
96|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
97|801 | Capability not supported.          |
98|2900001 | Service stopped.                         |
99|2900003 | Bluetooth disabled.                 |
100|2900004 | Profile not supported.                |
101|2900099 | Operation failed.                        |
102
103**Example**
104
105```js
106import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
107try {
108    let mapMseProfile = map.createMapMseProfile();
109    mapMseProfile.setMessageAccessAuthorization('XX:XX:XX:XX:XX:XX', 0).then(() => {
110        console.info('setMessageAccessAuthorization');
111    });
112} catch (err) {
113    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
114}
115```
116
117### getMessageAccessAuthorization
118
119getMessageAccessAuthorization(deviceId: string): Promise<AccessAuthorization>
120
121Obtains the message access authorization of a device. This API uses a promise to return the result.
122
123**System API**: This is a system API.
124
125**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
126
127**System capability**: SystemCapability.Communication.Bluetooth.Core
128
129**Parameters**
130
131| Name     | Type    | Mandatory  | Description                                 |
132| -------- | ------ | ---- | ----------------------------------- |
133| deviceId | string | Yes   | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
134
135**Return value**
136
137| Type                                             | Description               |
138| ------------------------------------------------- | ------------------- |
139| Promise<[AccessAuthorization](js-apis-bluetooth-constant-sys.md#AccessAuthorization)> | Promise used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
140
141**Error codes**
142
143For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md).
144
145| ID| Error Message|
146| -------- | ---------------------------- |
147|201 | Permission denied.                 |
148|202 | Non-system applications are not allowed to use system APIs. |
149|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
150|801 | Capability not supported.          |
151|2900001 | Service stopped.                         |
152|2900003 | Bluetooth disabled.                 |
153|2900004 | Profile not supported.                |
154|2900099 | Operation failed.                        |
155
156**Example**
157
158```js
159import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
160try {
161    let mapMseProfile = map.createMapMseProfile();
162    mapMseProfile.getMessageAccessAuthorization('XX:XX:XX:XX:XX:XX').then((authorization) => {
163        console.info('authorization ' + authorization);
164    });
165} catch (err) {
166    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
167}
168```
169