1# @ohos.bluetooth.map (蓝牙map模块)(系统接口)
2
3map模块提供了访问信息相关功能的方法。
4
5> **说明:**
6>
7> 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.bluetooth.map (蓝牙map模块)](js-apis-bluetooth-map.md)
9
10
11## 导入模块
12
13```js
14import { map } from '@kit.ConnectivityKit';
15```
16
17
18### disconnect
19
20disconnect(deviceId: string): void
21
22断开连接设备的map服务。
23
24**系统接口**:此接口为系统接口。
25
26**需要权限**:ohos.permission.ACCESS_BLUETOOTH
27
28**系统能力**:SystemCapability.Communication.Bluetooth.Core29
30**参数:**
31
32| 参数名    | 类型     | 必填   | 说明      |
33| ------ | ------ | ---- | ------- |
34| deviceId | string | 是    | 远端设备地址。 |
35
36**错误码**:
37
38以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
39
40| 错误码ID | 错误信息 |
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**示例:**
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
67设置信息的访问权限。使用Promise异步回调。
68
69**系统接口**:此接口为系统接口。
70
71**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
72
73**系统能力**:SystemCapability.Communication.Bluetooth.Core74
75**参数:**
76
77| 参数名      | 类型     | 必填   | 说明                                  |
78| -------- | ------ | ---- | ----------------------------------- |
79| deviceId | string | 是    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
80| authorization | [AccessAuthorization](js-apis-bluetooth-constant-sys.md#AccessAuthorization) | 是    | 表示访问权限枚举值。 |
81
82**返回值:**
83
84| 类型                                              | 说明                |
85| ------------------------------------------------- | ------------------- |
86| Promise<void> | 以Promise的形式返回结果。如果成功,err为undefined的,否则为错误对象。 |
87
88**错误码**:
89
90以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
91
92| 错误码ID | 错误信息 |
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**示例:**
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
121获取信息的访问权限。使用Promise异步回调。
122
123**系统接口**:此接口为系统接口。
124
125**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
126
127**系统能力**:SystemCapability.Communication.Bluetooth.Core128
129**参数:**
130
131| 参数名      | 类型     | 必填   | 说明                                  |
132| -------- | ------ | ---- | ----------------------------------- |
133| deviceId | string | 是    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
134
135**返回值:**
136
137| 类型                                              | 说明                |
138| ------------------------------------------------- | ------------------- |
139| Promise<[AccessAuthorization](js-apis-bluetooth-constant-sys.md#AccessAuthorization)> | 以Promise的形式返回结果。如果成功,err为undefined的,否则为错误对象。 |
140
141**错误码**:
142
143以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
144
145| 错误码ID | 错误信息 |
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**示例:**
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```