Bluetooth Changelog

cl.bluetooth.1 Split of Bluetooth APIs by Profile

  1. Split ArkTS APIs in corresponding .d.ts files.
  2. Changed the interface permission to ohos.permission.ACCESS_BLUETOOTH. Some APIs also require the ohos.permission.MANAGE_BLUETOOTH permission.
Module API Reference
@ohos.bluetooth.a2dp js-apis-bluetooth-a2dp.md
@ohos.bluetooth.access js-apis-bluetooth-access.md
@ohos.bluetooth.baseProfile js-apis-bluetooth-baseProfile.md
@ohos.bluetooth.ble js-apis-bluetooth-ble.md
@ohos.bluetooth.connection js-apis-bluetooth-connection.md
@ohos.bluetooth.constant js-apis-bluetooth-constant.md
@ohos.bluetooth.hfp js-apis-bluetooth-hfp.md
@ohos.bluetooth.hid js-apis-bluetooth-hid.md
@ohos.bluetooth.pan js-apis-bluetooth-pan.md
@ohos.bluetooth.socket js-apis-bluetooth-socket.md

APIs Requiring Dual-Permission Verification

Module API
@ohos.bluetooth.baseProfile setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy, callback: AsyncCallback<void>): void
@ohos.bluetooth.baseProfile setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy): Promise<void>
@ohos.bluetooth.baseProfile getConnectionStrategy(deviceId: string, callback: AsyncCallback<ConnectionStrategy>): void
@ohos.bluetooth.baseProfile getConnectionStrategy(deviceId: string): Promise<ConnectionStrategy>
@ohos.bluetooth.connection pairCredibleDevice(deviceId: string, transport: BluetoothTransport, callback: AsyncCallback<void>): void
@ohos.bluetooth.connection pairCredibleDevice(deviceId: string, transport: BluetoothTransport): Promise<void>
@ohos.bluetooth.connection setDevicePairingConfirmation(deviceId: string, accept: boolean): void
connect(hid profile) connect(deviceId: string): void
disconnect(hid profile) disconnect(deviceId: string): void
setTethering setTethering(enable: boolean): void

Change Impact

  1. The module to import is changed.
  2. After the permission change, only the ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH permissions are required.

Key API/Component Changes

Before Change After Change
bluetoothManager.enableBluetooth access.enableBluetooth
bluetoothManager.disableBluetooth access.disableBluetooth
bluetoothManager.getLocalName connection.getLocalName
bluetoothManager.getState access.getState
bluetoothManager.getBtConnectionState connection.getProfileConnectionState
bluetoothManager.setLocalName connection.setLocalName
bluetoothManager.pairDevice connection.pairDevice
bluetoothManager.getProfileConnectionState connection.getProfileConnectionState
bluetoothManager.cancelPairedDevice connection.cancelPairedDevice
bluetoothManager.getRemoteDeviceName connection.getRemoteDeviceName
bluetoothManager.getRemoteDeviceClass connection.getRemoteDeviceClass
bluetoothManager.getPairedDevices connection.getPairedDevices
bluetoothManager.setBluetoothScanMode connection.setBluetoothScanMode
bluetoothManager.getBluetoothScanMode connection.getBluetoothScanMode
bluetoothManager.startBluetoothDiscovery connection.startBluetoothDiscovery
bluetoothManager.stopBluetoothDiscovery connection.stopBluetoothDiscovery
bluetoothManager.setDevicePairingConfirmation connection.setDevicePairingConfirmation
bluetoothManager.on('bluetoothDeviceFind') connection.on('bluetoothDeviceFind')
bluetoothManager.off('bluetoothDeviceFind') connection.off('bluetoothDeviceFind')
bluetoothManager.on('pinRequired') connection.on('pinRequired')
bluetoothManager.off('pinRequired') connection.off('pinRequired')
bluetoothManager.on('bondStateChange') connection.on('bondStateChange')
bluetoothManager.off('bondStateChange') connection.off('bondStateChange')
bluetoothManager.on('stateChange') access.on('stateChange')
bluetoothManager.off('stateChange') access.off('stateChange')
bluetoothManager.sppListen socket.sppListen
bluetoothManager.sppAccept socket.sppAccept
bluetoothManager.sppConnect socket.sppConnect
bluetoothManager.sppCloseServerSocket socket.sppCloseServerSocket
bluetoothManager.sppCloseClientSocket socket.sppCloseClientSocket
bluetoothManager.sppWrite socket.sppWrite
bluetoothManager.on('sppRead') socket.on('sppRead')
bluetoothManager.off('sppRead') socket.off('sppRead')
bluetoothManager.getProfileInstance Deprecated
createGattServer ble.createGattServer
createGattClientDevice ble.createGattClientDevice
getConnectedBLEDevices ble.getConnectedBLEDevices
startBLEScan ble.startBLEScan
stopBLEScan ble.stopBLEScan
on('BLEDeviceFind') ble.on('BLEDeviceFind')
off('BLEDeviceFind') ble.off('BLEDeviceFind')
getConnectionDevices baseProfile.getConnectedDevices
getDeviceState baseProfile.getConnectionState
A2dpSourceProfile A2dpSourceProfile
connect(a2dp profile) connect
disconnect(a2dp profile) disconnect
on('connectionStateChange') baseProfile.on('connectionStateChange')
off('connectionStateChange') baseProfile.off('connectionStateChange')
getPlayingState getPlayingState
HandsFreeAudioGatewayProfile HandsFreeAudioGatewayProfile
connect(hfp profile) connect
disconnect(hfp profile) disconnect
on('connectionStateChange')(hfp profile) baseProfile.on('connectionStateChange')
off('connectionStateChange')(hfp profile) baseProfile.off('connectionStateChange')
connect(hid profile) connect
disconnect(hid profile) disconnect
on('connectionStateChange')(hid profile) baseProfile.on('connectionStateChange')
off('connectionStateChange')(hid profile) baseProfile.off('connectionStateChange')
disconnect(pan profile) disconnect
on('connectionStateChange')(pan profile) baseProfile.on('connectionStateChange')
off('connectionStateChange')(pan profile) baseProfile.off('connectionStateChange')
setTethering setTethering
isTetheringOn isTetheringOn
startAdvertising ble.startAdvertising
stopAdvertising ble.stopAdvertising
addService addService
removeService removeService
close close
notifyCharacteristicChanged notifyCharacteristicChanged
sendResponse sendResponse
on('characteristicRead') on('characteristicRead')
off('characteristicRead') off('characteristicRead')
on('characteristicWrite') on('characteristicWrite')
off('characteristicWrite') off('characteristicWrite')
on('descriptorRead') on('descriptorRead')
off('descriptorRead') off('descriptorRead')
on('descriptorWrite') on('descriptorWrite')
off('descriptorWrite') off('descriptorWrite')
on('connectStateChange') on('connectionStateChange')
off('connectStateChange') off('connectionStateChange')
connect connect
disconnect disconnect
close close
getServices(callback) getServices
getServices(promise) getServices
readCharacteristicValue(callback) readCharacteristicValue
readCharacteristicValue(promise) readCharacteristicValue
readDescriptorValue(callback) readDescriptorValue
readDescriptorValue(promise) readDescriptorValue
writeCharacteristicValue(callback) writeCharacteristicValue
writeDescriptorValue(promise) writeCharacteristicValue
setBLEMtuSize setBLEMtuSize
setNotifyCharacteristicChanged setCharacteristicChangeNotification
on('BLECharacteristicChange') on('BLECharacteristicChange')
off('BLECharacteristicChange') off('BLECharacteristicChange')
on('BLEConnectionStateChange') on('BLEConnectionStateChange')
off('BLEConnectionStateChange') off('BLEConnectionStateChange')
getDeviceName(callback) getDeviceName
getDeviceName(promise) getDeviceName
getRssiValue(callback) getRssiValue
getRssiValue(promise) getRssiValue
ScanMode ScanMode
BondState BondState
SppOption SppOptions
SppType SppType
GattService GattService
BLECharacteristic BLECharacteristic
BLEDescriptor BLEDescriptor
NotifyCharacteristic NotifyCharacteristic
CharacteristicReadRequest CharacteristicReadRequest
CharacteristicWriteRequest CharacteristicWriteRequest
DescriptorReadRequest DescriptorReadRequest
DescriptorWriteRequest DescriptorWriteRequest
ServerResponse ServerResponse
BLEConnectChangedState BLEConnectionChangeState
ProfileConnectionState ProfileConnectionState
ScanFilter ScanFilter
ScanOptions ScanOptions
ScanDuty ScanDuty
MatchMode MatchMode
ScanResult ScanResult
BluetoothState BluetoothState
AdvertiseSetting AdvertiseSetting
AdvertiseData AdvertiseData
ManufactureData ManufactureData
ServiceData ServiceData
PinRequiredParam PinRequiredParam
BondStateParam BondStateParam
StateChangeParam StateChangeParam
DeviceClass DeviceClass
MajorClass MajorClass
MajorMinorClass MajorMinorClass
PlayingState PlayingState
ProfileId ProfileId

Added APIs

Module API
@ohos.bluetooth.connection pairCredibleDevice(deviceId: string, transport: BluetoothTransport, callback: AsyncCallback<void>): void
@ohos.bluetooth.connection pairCredibleDevice(deviceId: string, transport: BluetoothTransport): Promise<void>
@ohos.bluetooth.connection getRemoteProfileUuids(deviceId: string, callback: AsyncCallback<Array<ProfileUuids>>): void
@ohos.bluetooth.connection getRemoteProfileUuids(deviceId: string): Promise<Array<ProfileUuids>>
@ohos.bluetooth.connection getLocalProfileUuids(callback: AsyncCallback<Array<ProfileUuids>>): void
@ohos.bluetooth.connection getLocalProfileUuids(): Promise<Array<ProfileUuids>>
@ohos.bluetooth.connection setDevicePinCode(deviceId: string, code: string, callback: AsyncCallback<void>): void
@ohos.bluetooth.connection setDevicePinCode(deviceId: string, code: string): Promise<void>
@ohos.bluetooth.baseProfile setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy, callback: AsyncCallback<void>): void
@ohos.bluetooth.baseProfile setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy): Promise<void>
@ohos.bluetooth.baseProfile getConnectionStrategy(deviceId: string, callback: AsyncCallback<ConnectionStrategy>): void
@ohos.bluetooth.baseProfile getConnectionStrategy(deviceId: string): Promise<ConnectionStrategy>
@ohos.bluetooth.baseprofile ConnectionStrategy
@ohos.bluetooth.ble properties
@ohos.bluetooth.ble deviceName
@ohos.bluetooth.ble includeDeviceName
@ohos.bluetooth.ble GattProperties
@ohos.bluetooth.ble setCharacteristicChangeIndication(characteristic: BLECharacteristic, enable: boolean, callback: AsyncCallback<void>): void
@ohos.bluetooth.ble setCharacteristicChangeIndication(characteristic: BLECharacteristic, enable: boolean): Promise<void>
@ohos.bluetooth.ble on(type: 'BLEMtuChange', callback: Callback<number>): void
@ohos.bluetooth.ble off(type: 'BLEMtuChange', callback?: Callback<number>): void
@ohos.bluetooth.connection pinType
@ohos.bluetooth.connection BluetoothTransport
@ohos.bluetooth.constant ProfileUuids

APIs Added with Promise

Module API
@ohos.bluetooth.ble notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic): Promise<void>
@ohos.bluetooth.ble writeCharacteristicValue(characteristic: BLECharacteristic, writeType: GattWriteType): Promise<void>
@ohos.bluetooth.ble writeDescriptorValue(descriptor: BLEDescriptor): Promise<void>
@ohos.bluetooth.ble setCharacteristicChangeNotification(characteristic: BLECharacteristic, enable: boolean): Promise<void>

Adaptation Guide

Determine the module to import based on the profile module. For some interfaces, multiple TS files need to be imported.

//For example, getConnectionState() in @ohos.bluetooth.baseProfile.
import a2dp from '@ohos.bluetooth.a2dp';
try {
    let a2dpSrc = a2dp.createA2dpSrcProfile();
    let ret = a2dpSrc.getConnectionState('XX:XX:XX:XX:XX:XX');
} catch (err) {
    console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}