1# @ohos.bluetooth.map (蓝牙map模块)(系统接口) 2 3<!--Kit: Connectivity Kit--> 4<!--Subsystem: Communication--> 5<!--Owner: @enjoy_sunshine--> 6<!--Designer: @chengguohong; @tangjia15--> 7<!--Tester: @wangfeng517--> 8<!--Adviser: @zhang_yixin13--> 9 10map模块提供了访问信息相关功能的方法。 11 12> **说明:** 13> 14> 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 15> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.bluetooth.map (蓝牙map模块)](js-apis-bluetooth-map.md)。 16 17 18## 导入模块 19 20```js 21import { map } from '@kit.ConnectivityKit'; 22``` 23 24 25### disconnect 26 27disconnect(deviceId: string): void 28 29断开连接设备的map服务。 30 31**系统接口**:此接口为系统接口。 32 33**需要权限**:ohos.permission.ACCESS_BLUETOOTH 34 35**系统能力**:SystemCapability.Communication.Bluetooth.Core 36 37**参数:** 38 39| 参数名 | 类型 | 必填 | 说明 | 40| ------ | ------ | ---- | ------- | 41| deviceId | string | 是 | 远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 | 42 43**错误码**: 44 45以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 46 47| 错误码ID | 错误信息 | 48| -------- | ---------------------------- | 49|201 | Permission denied. | 50|202 | Non-system applications are not allowed to use system APIs. | 51|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 52|801 | Capability not supported. | 53|2900001 | Service stopped. | 54|2900003 | Bluetooth disabled. | 55|2900004 | Profile not supported. | 56|2900099 | Operation failed. | 57 58**示例:** 59 60```js 61import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 62try { 63 let mapMseProfile = map.createMapMseProfile(); 64 mapMseProfile.disconnect('XX:XX:XX:XX:XX:XX'); 65} catch (err) { 66 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 67} 68``` 69 70### setMessageAccessAuthorization 71 72setMessageAccessAuthorization(deviceId: string, authorization: AccessAuthorization): Promise<void> 73 74设置信息的访问权限。使用Promise异步回调。 75 76**系统接口**:此接口为系统接口。 77 78**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 79 80**系统能力**:SystemCapability.Communication.Bluetooth.Core 81 82**参数:** 83 84| 参数名 | 类型 | 必填 | 说明 | 85| -------- | ------ | ---- | ----------------------------------- | 86| deviceId | string | 是 | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 | 87| authorization | [AccessAuthorization](js-apis-bluetooth-constant-sys.md#accessauthorization11) | 是 | 表示访问权限枚举值。 | 88 89**返回值:** 90 91| 类型 | 说明 | 92| ------------------------------------------------- | ------------------- | 93| Promise<void> | 以Promise的形式返回结果。如果成功,err为undefined,否则为错误对象。 | 94 95**错误码**: 96 97以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 98 99| 错误码ID | 错误信息 | 100| -------- | ---------------------------- | 101|201 | Permission denied. | 102|202 | Non-system applications are not allowed to use system APIs. | 103|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 104|801 | Capability not supported. | 105|2900001 | Service stopped. | 106|2900003 | Bluetooth disabled. | 107|2900004 | Profile not supported. | 108|2900099 | Operation failed. | 109 110**示例:** 111 112```js 113import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 114try { 115 let mapMseProfile = map.createMapMseProfile(); 116 mapMseProfile.setMessageAccessAuthorization('XX:XX:XX:XX:XX:XX', 0).then(() => { 117 console.info('setMessageAccessAuthorization'); 118 }); 119} catch (err) { 120 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 121} 122``` 123 124### getMessageAccessAuthorization 125 126getMessageAccessAuthorization(deviceId: string): Promise<AccessAuthorization> 127 128获取信息的访问权限。使用Promise异步回调。 129 130**系统接口**:此接口为系统接口。 131 132**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 133 134**系统能力**:SystemCapability.Communication.Bluetooth.Core 135 136**参数:** 137 138| 参数名 | 类型 | 必填 | 说明 | 139| -------- | ------ | ---- | ----------------------------------- | 140| deviceId | string | 是 | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 | 141 142**返回值:** 143 144| 类型 | 说明 | 145| ------------------------------------------------- | ------------------- | 146| Promise<[AccessAuthorization](js-apis-bluetooth-constant-sys.md#accessauthorization11)> | 以Promise的形式返回结果。如果成功,err为undefined,否则为错误对象。 | 147 148**错误码**: 149 150以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 151 152| 错误码ID | 错误信息 | 153| -------- | ---------------------------- | 154|201 | Permission denied. | 155|202 | Non-system applications are not allowed to use system APIs. | 156|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 157|801 | Capability not supported. | 158|2900001 | Service stopped. | 159|2900003 | Bluetooth disabled. | 160|2900004 | Profile not supported. | 161|2900099 | Operation failed. | 162 163**示例:** 164 165```js 166import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 167try { 168 let mapMseProfile = map.createMapMseProfile(); 169 mapMseProfile.getMessageAccessAuthorization('XX:XX:XX:XX:XX:XX').then((authorization) => { 170 console.info('authorization ' + authorization); 171 }); 172} catch (err) { 173 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 174} 175```