• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 '@ohos.bluetooth.map';
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|2900001 | Service stopped.                         |
43|2900003 | Bluetooth switch is off.                 |
44|2900004 | Profile is not supported.                |
45|2900099 | Operation failed.                        |
46
47**示例:**
48
49```js
50import { BusinessError } from '@ohos.base';
51try {
52    let mapMseProfile = map.createMapMseProfile();
53    mapMseProfile.disconnect('XX:XX:XX:XX:XX:XX');
54} catch (err) {
55    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
56}
57```
58
59### setMessageAccessAuthorization
60
61setMessageAccessAuthorization(deviceId: string, authorization: AccessAuthorization): Promise<void>
62
63设置信息的访问权限。
64
65**系统接口**:此接口为系统接口。
66
67**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
68
69**系统能力**:SystemCapability.Communication.Bluetooth.Core70
71**参数:**
72
73| 参数名      | 类型     | 必填   | 说明                                  |
74| -------- | ------ | ---- | ----------------------------------- |
75| deviceId | string | 是    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
76| authorization | [AccessAuthorization](js-apis-bluetooth-constant-sys.md#AccessAuthorization) | 是    | 表示访问权限枚举值。 |
77
78**返回值:**
79
80| 类型                                              | 说明                |
81| ------------------------------------------------- | ------------------- |
82| Promise<void> | 以Promise的形式返回结果。如果成功,err为undefined的,否则为错误对象。 |
83
84**错误码**:
85
86以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
87
88| 错误码ID | 错误信息 |
89| -------- | ---------------------------- |
90|2900001 | Service stopped.                         |
91|2900003 | Bluetooth switch is off.                 |
92|2900004 | Profile is not supported.                |
93|2900099 | Operation failed.                        |
94
95**示例:**
96
97```js
98import { BusinessError } from '@ohos.base';
99try {
100    let mapMseProfile = map.createMapMseProfile();
101    mapMseProfile.setMessageAccessAuthorization('XX:XX:XX:XX:XX:XX', 0).then(() => {
102        console.info('setMessageAccessAuthorization');
103    });
104} catch (err) {
105    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
106}
107```
108
109### getMessageAccessAuthorization
110
111getMessageAccessAuthorization(deviceId: string): Promise<AccessAuthorization>
112
113获取信息的访问权限。
114
115**系统接口**:此接口为系统接口。
116
117**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
118
119**系统能力**:SystemCapability.Communication.Bluetooth.Core120
121**参数:**
122
123| 参数名      | 类型     | 必填   | 说明                                  |
124| -------- | ------ | ---- | ----------------------------------- |
125| deviceId | string | 是    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
126
127**返回值:**
128
129| 类型                                              | 说明                |
130| ------------------------------------------------- | ------------------- |
131| Promise<[AccessAuthorization](js-apis-bluetooth-constant-sys.md#AccessAuthorization)> | 以Promise的形式返回结果。如果成功,err为undefined的,否则为错误对象。 |
132
133**错误码**:
134
135以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
136
137| 错误码ID | 错误信息 |
138| -------- | ---------------------------- |
139|2900001 | Service stopped.                         |
140|2900003 | Bluetooth switch is off.                 |
141|2900004 | Profile is not supported.                |
142|2900099 | Operation failed.                        |
143
144**示例:**
145
146```js
147import { BusinessError } from '@ohos.base';
148try {
149    let mapMseProfile = map.createMapMseProfile();
150    mapMseProfile.getMessageAccessAuthorization('XX:XX:XX:XX:XX:XX').then((authorization) => {
151        console.info('authorization ' + authorization);
152    });
153} catch (err) {
154    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
155}
156```