1# @ohos.bluetooth.map (Bluetooth MAP Module) 2 3The **bluetooth.map** module provides APIs for exchanging messages between devices. 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 9 10 11## Modules to Import 12 13```js 14import map from '@ohos.bluetooth.map'; 15``` 16 17 18## map.createMapMseProfile 19 20createMapMseProfile(): MapMseProfile 21 22Creates a **MapMseProfile** instance. 23 24**System capability**: SystemCapability.Communication.Bluetooth.Core 25 26**Return value** 27 28| Type | Description | 29| ----------------------------- | ---------- | 30| MapMseProfile | **MapMseProfile** instance created.| 31 32**Example** 33 34```js 35import { BusinessError } from '@ohos.base'; 36try { 37 let mapMseProfile = map.createMapMseProfile(); 38 console.info('MapMse success'); 39} catch (err) { 40 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 41} 42``` 43 44 45## mapMseProfile 46 47Provides APIs for exchanging messages between devices using the Bluetooth Message Access Profile (MAP). Before using any API of **mapMseProfile**, you need to create an instance of this class by using **createMapMseProfile()**. 48 49 50### disconnect 51 52disconnect(deviceId: string): void 53 54Disconnects the MAP service for a device. 55 56**System API**: This is a system API. 57 58**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 59 60**System capability**: SystemCapability.Communication.Bluetooth.Core 61 62**Parameters** 63 64| Name | Type | Mandatory | Description | 65| ------ | ------ | ---- | ------- | 66| deviceId | string | Yes | Address of the remote device.| 67 68**Error codes** 69 70For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md). 71 72| ID| Error Message| 73| -------- | ---------------------------- | 74|2900001 | Service stopped. | 75|2900003 | Bluetooth switch is off. | 76|2900004 | Profile is not supported. | 77|2900099 | Operation failed. | 78 79**Example** 80 81```js 82import { BusinessError } from '@ohos.base'; 83try { 84 let mapMseProfile = map.createMapMseProfile(); 85 mapMseProfile.disconnect('XX:XX:XX:XX:XX:XX'); 86} catch (err) { 87 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 88} 89``` 90 91### setMessageAccessAuthorization 92 93setMessageAccessAuthorization(deviceId: string, authorization: AccessAuthorization): Promise<void> 94 95Sets the message access authorization for a device. 96 97**System API**: This is a system API. 98 99**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 100 101**System capability**: SystemCapability.Communication.Bluetooth.Core 102 103**Parameters** 104 105| Name | Type | Mandatory | Description | 106| -------- | ------ | ---- | ----------------------------------- | 107| deviceId | string | Yes | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.| 108| authorization | [AccessAuthorization](js-apis-bluetooth-constant.md#AccessAuthorization) | Yes | Message access authorization to set.| 109 110**Return value** 111 112| Type | Description | 113| ------------------------------------------------- | ------------------- | 114| Promise<void> | Promise used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 115 116**Error codes** 117 118For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md). 119 120| ID| Error Message| 121| -------- | ---------------------------- | 122|2900001 | Service stopped. | 123|2900003 | Bluetooth switch is off. | 124|2900004 | Profile is not supported. | 125|2900099 | Operation failed. | 126 127**Example** 128 129```js 130import { BusinessError } from '@ohos.base'; 131try { 132 let mapMseProfile = map.createMapMseProfile(); 133 mapMseProfile.setMessageAccessAuthorization('XX:XX:XX:XX:XX:XX', 0).then(() => { 134 console.info('setMessageAccessAuthorization'); 135 }); 136} catch (err) { 137 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 138} 139``` 140 141### getMessageAccessAuthorization 142 143getMessageAccessAuthorization(deviceId: string): Promise<AccessAuthorization> 144 145Obtains the message access authorization of a device. 146 147**System API**: This is a system API. 148 149**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 150 151**System capability**: SystemCapability.Communication.Bluetooth.Core 152 153**Parameters** 154 155| Name | Type | Mandatory | Description | 156| -------- | ------ | ---- | ----------------------------------- | 157| deviceId | string | Yes | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.| 158 159**Return value** 160 161| Type | Description | 162| ------------------------------------------------- | ------------------- | 163| Promise<[AccessAuthorization](js-apis-bluetooth-constant.md#AccessAuthorization)> | Promise used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 164 165**Error codes** 166 167For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md). 168 169| ID| Error Message| 170| -------- | ---------------------------- | 171|2900001 | Service stopped. | 172|2900003 | Bluetooth switch is off. | 173|2900004 | Profile is not supported. | 174|2900099 | Operation failed. | 175 176**Example** 177 178```js 179import { BusinessError } from '@ohos.base'; 180try { 181 let mapMseProfile = map.createMapMseProfile(); 182 mapMseProfile.getMessageAccessAuthorization('XX:XX:XX:XX:XX:XX').then((authorization) => { 183 console.info('authorization ' + authorization); 184 }); 185} catch (err) { 186 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 187} 188``` 189