openharmony 鸿蒙 changelogs-bluetooth

2023-10-30 浏览 (515)

bluetooth子系统ChangeLog

cl.bluetooth.1 蓝牙模块JS接口拆分,支持按profile加载接口能力。

  1. ArkTS接口,拆分在对应的.d.ts中。
  2. 权限变更,接口权限统一变更为ohos.permission.ACCESS_BLUETOOTH,部分接口额外需要ohos.permission.MANAGE_BLUETOOTH权限。
模块接口文档
@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

需要双权限校验的接口

模块接口声明
@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

变更影响

  1. TS拆分后,接口调用import文件发生改变。
  2. 权限变更后,只需关注ohos.permission.ACCESS_BLUETOOTH和ohos.permission.MANAGE_BLUETOOTH权限。

关键接口/组件变更

拆分前拆分后
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.getProfileInstance已废弃
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

新增接口声明

模块名新增声明
@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

补充promise调用方式

模块名新增声明
@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>

适配指导

注意根据不同profile模块选择import方式,部分接口需要import多个TS文件。

//例如@ohos.bluetooth.baseProfile下getConnectionState接口。
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子系统changelog

harmony 鸿蒙程序访问控制子系统ChangeLog

harmony 鸿蒙帐号子系统ChangeLog

harmony 鸿蒙包管理子系统ChangeLog

harmony 鸿蒙安全子系统ChangeLog

harmony 鸿蒙图形子系统ChangeLog

harmony 鸿蒙输入法框架子系统-输入法框架ChangeLog

harmony 鸿蒙电话子系统ChangeLog

harmony 鸿蒙wifi子系统ChangeLog

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