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