openharmony 鸿蒙 changelogs-bluetooth

2023-10-30 浏览 (281)

Bluetooth Subsystem 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.
ModuleAPI Reference
@ohos.bluetooth.a2dpjs-apis-bluetooth-a2dp.md
@ohos.bluetooth.accessjs-apis-bluetooth-access.md
@ohos.bluetooth.baseProfilejs-apis-bluetooth-baseProfile.md
@ohos.bluetooth.blejs-apis-bluetooth-ble.md
@ohos.bluetooth.connectionjs-apis-bluetooth-connection.md
@ohos.bluetooth.constantjs-apis-bluetooth-constant.md
@ohos.bluetooth.hfpjs-apis-bluetooth-hfp.md
@ohos.bluetooth.hidjs-apis-bluetooth-hid.md
@ohos.bluetooth.panjs-apis-bluetooth-pan.md
@ohos.bluetooth.socketjs-apis-bluetooth-socket.md

APIs Requiring Dual-Permission Verification

ModuleAPI Declaration
@ohos.bluetooth.baseProfilesetConnectionStrategy(deviceId: string, strategy: ConnectionStrategy, callback: AsyncCallback<void>): void
@ohos.bluetooth.baseProfilesetConnectionStrategy(deviceId: string, strategy: ConnectionStrategy): Promise<void>
@ohos.bluetooth.baseProfilegetConnectionStrategy(deviceId: string, callback: AsyncCallback<ConnectionStrategy>): void
@ohos.bluetooth.baseProfilegetConnectionStrategy(deviceId: string): Promise<ConnectionStrategy>
@ohos.bluetooth.connectionpairCredibleDevice(deviceId: string, transport: BluetoothTransport, callback: AsyncCallback<void>): void
@ohos.bluetooth.connectionpairCredibleDevice(deviceId: string, transport: BluetoothTransport): Promise<void>
@ohos.bluetooth.connectionsetDevicePairingConfirmation(deviceId: string, accept: boolean): void
connect(hid profile)connect(deviceId: string): void
disconnect(hid profile)disconnect(deviceId: string): void
setTetheringsetTethering(enable: boolean): void

Change Impact

  1. The module to import is changed.
  2. After the permission change, you only need to pay attention to the ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH permissions.

Key API/Component Changes

Before ChangeAfter Change
bluetoothManager.enableBluetoothaccess.enableBluetooth
bluetoothManager.disableBluetoothaccess.disableBluetooth
bluetoothManager.getLocalNameconnection.getLocalName
bluetoothManager.getStateaccess.getState
bluetoothManager.getBtConnectionStateconnection.getProfileConnectionState
bluetoothManager.setLocalNameconnection.setLocalName
bluetoothManager.pairDeviceconnection.pairDevice
bluetoothManager.getProfileConnectionStateconnection.getProfileConnectionState
bluetoothManager.cancelPairedDeviceconnection.cancelPairedDevice
bluetoothManager.getRemoteDeviceNameconnection.getRemoteDeviceName
bluetoothManager.getRemoteDeviceClassconnection.getRemoteDeviceClass
bluetoothManager.getPairedDevicesconnection.getPairedDevices
bluetoothManager.setBluetoothScanModeconnection.setBluetoothScanMode
bluetoothManager.getBluetoothScanModeconnection.getBluetoothScanMode
bluetoothManager.startBluetoothDiscoveryconnection.startBluetoothDiscovery
bluetoothManager.stopBluetoothDiscoveryconnection.stopBluetoothDiscovery
bluetoothManager.setDevicePairingConfirmationconnection.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.sppListensocket.sppListen
bluetoothManager.sppAcceptsocket.sppAccept
bluetoothManager.sppConnectsocket.sppConnect
bluetoothManager.sppCloseServerSocketsocket.sppCloseServerSocket
bluetoothManager.sppCloseClientSocketsocket.sppCloseClientSocket
bluetoothManager.sppWritesocket.sppWrite
bluetoothManager.on('sppRead')socket.on('sppRead')
bluetoothManager.off('sppRead')socket.off('sppRead')
bluetoothManager.getProfileInstanceDeprecated
createGattServerble.createGattServer
createGattClientDeviceble.createGattClientDevice
getConnectedBLEDevicesble.getConnectedBLEDevices
startBLEScanble.startBLEScan
stopBLEScanble.stopBLEScan
on('BLEDeviceFind')ble.on('BLEDeviceFind')
off('BLEDeviceFind')ble.off('BLEDeviceFind')
getConnectionDevicesbaseProfile.getConnectedDevices
getDeviceStatebaseProfile.getConnectionState
A2dpSourceProfileA2dpSourceProfile
connect(a2dp profile)connect
disconnect(a2dp profile)disconnect
on('connectionStateChange')baseProfile.on('connectionStateChange')
off('connectionStateChange')baseProfile.off('connectionStateChange')
getPlayingStategetPlayingState
HandsFreeAudioGatewayProfileHandsFreeAudioGatewayProfile
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')
setTetheringsetTethering
isTetheringOnisTetheringOn
startAdvertisingble.startAdvertising
stopAdvertisingble.stopAdvertising
addServiceaddService
removeServiceremoveService
closeclose
notifyCharacteristicChangednotifyCharacteristicChanged
sendResponsesendResponse
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')
connectconnect
disconnectdisconnect
closeclose
getServices(callback)getServices
getServices(promise)getServices
readCharacteristicValue(callback)readCharacteristicValue
readCharacteristicValue(promise)readCharacteristicValue
readDescriptorValue(callback)readDescriptorValue
readDescriptorValue(promise)readDescriptorValue
writeCharacteristicValue(callback)writeCharacteristicValue
writeDescriptorValue(promise)writeCharacteristicValue
setBLEMtuSizesetBLEMtuSize
setNotifyCharacteristicChangedsetCharacteristicChangeNotification
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
ScanModeScanMode
BondStateBondState
SppOptionSppOptions
SppTypeSppType
GattServiceGattService
BLECharacteristicBLECharacteristic
BLEDescriptorBLEDescriptor
NotifyCharacteristicNotifyCharacteristic
CharacteristicReadRequestCharacteristicReadRequest
CharacteristicWriteRequestCharacteristicWriteRequest
DescriptorReadRequestDescriptorReadRequest
DescriptorWriteRequestDescriptorWriteRequest
ServerResponseServerResponse
BLEConnectChangedStateBLEConnectionChangeState
ProfileConnectionStateProfileConnectionState
ScanFilterScanFilter
ScanOptionsScanOptions
ScanDutyScanDuty
MatchModeMatchMode
ScanResultScanResult
BluetoothStateBluetoothState
AdvertiseSettingAdvertiseSetting
AdvertiseDataAdvertiseData
ManufactureDataManufactureData
ServiceDataServiceData
PinRequiredParamPinRequiredParam
BondStateParamBondStateParam
StateChangeParamStateChangeParam
DeviceClassDeviceClass
MajorClassMajorClass
MajorMinorClassMajorMinorClass
PlayingStatePlayingState
ProfileIdProfileId

Added APIs

ModuleAPI
@ohos.bluetooth.connectionpairCredibleDevice(deviceId: string, transport: BluetoothTransport, callback: AsyncCallback<void>): void
@ohos.bluetooth.connectionpairCredibleDevice(deviceId: string, transport: BluetoothTransport): Promise<void>
@ohos.bluetooth.connectiongetRemoteProfileUuids(deviceId: string, callback: AsyncCallback<Array<ProfileUuids>>): void
@ohos.bluetooth.connectiongetRemoteProfileUuids(deviceId: string): Promise<Array<ProfileUuids>>
@ohos.bluetooth.connectiongetLocalProfileUuids(callback: AsyncCallback<Array<ProfileUuids>>): void
@ohos.bluetooth.connectiongetLocalProfileUuids(): Promise<Array<ProfileUuids>>
@ohos.bluetooth.connectionsetDevicePinCode(deviceId: string, code: string, callback: AsyncCallback<void>): void
@ohos.bluetooth.connectionsetDevicePinCode(deviceId: string, code: string): Promise<void>
@ohos.bluetooth.baseProfilesetConnectionStrategy(deviceId: string, strategy: ConnectionStrategy, callback: AsyncCallback<void>): void
@ohos.bluetooth.baseProfilesetConnectionStrategy(deviceId: string, strategy: ConnectionStrategy): Promise<void>
@ohos.bluetooth.baseProfilegetConnectionStrategy(deviceId: string, callback: AsyncCallback<ConnectionStrategy>): void
@ohos.bluetooth.baseProfilegetConnectionStrategy(deviceId: string): Promise<ConnectionStrategy>
@ohos.bluetooth.baseprofileConnectionStrategy
@ohos.bluetooth.bleproperties
@ohos.bluetooth.bledeviceName
@ohos.bluetooth.bleincludeDeviceName
@ohos.bluetooth.bleGattProperties
@ohos.bluetooth.blesetCharacteristicChangeIndication(characteristic: BLECharacteristic, enable: boolean, callback: AsyncCallback<void>): void
@ohos.bluetooth.blesetCharacteristicChangeIndication(characteristic: BLECharacteristic, enable: boolean): Promise<void>
@ohos.bluetooth.bleon(type: 'BLEMtuChange', callback: Callback<number>): void
@ohos.bluetooth.bleoff(type: 'BLEMtuChange', callback?: Callback<number>): void
@ohos.bluetooth.connectionpinType
@ohos.bluetooth.connectionBluetoothTransport
@ohos.bluetooth.constantProfileUuids

APIs Added with Promise

ModuleAPI
@ohos.bluetooth.blenotifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic): Promise<void>
@ohos.bluetooth.blewriteCharacteristicValue(characteristic: BLECharacteristic, writeType: GattWriteType): Promise<void>
@ohos.bluetooth.blewriteDescriptorValue(descriptor: BLEDescriptor): Promise<void>
@ohos.bluetooth.blesetCharacteristicChangeNotification(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);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkUI Subsystem Changelog

harmony 鸿蒙Application Access Control Subsystem Changelog

harmony 鸿蒙Account Subsystem Changelog

harmony 鸿蒙Bundle Management Subsystem Changelog

harmony 鸿蒙Security Subsystem Changelog

harmony 鸿蒙Graphics Subsystem Changelog

harmony 鸿蒙Input Method Framework Subsystem – Input Method Framework Service Changelog

harmony 鸿蒙Telephony Subsystem Changelog

harmony 鸿蒙Wi-Fi Subsystem Changelog

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/e59cc7d8d7bb44929b85dc63e3fc4a8c