想要设置蓝牙的Phy到2M (PHY_LE_2M_MASK)提高蓝牙数据的传输速度,但是uni没有提供相关的api
于是自己尝试用native.js设置,但是在连接gatt的时候一直有问题,返回值是null
let BluetoothDevice = plus.android.importClass('android.bluetooth.BluetoothDevice'),
bluetoothDevice = BAdapter.getRemoteDevice(deviceId),
mBluetoothGattCallback = plus.android.implements('io.dcloud.android.bluetooth.BluetoothGattCallback', {
onConnectionStateChange: function (gatt, status, newState) {
console.error("*******连接状态改变了")
console.error(gatt, status, newState)
},
onPhyUpdate: function (gatt, txPhy, rxPhy, status) {
console.error("*******phy更新了")
console.error(gatt, txPhy, rxPhy, status)
},
onMtuChanged: function (gatt, mtu, status) {
console.error("*******Mtu更新了")
console.error(gatt, mtu, status)
}
}),
mainActivity = plus.android.runtimeMainActivity(),
context = mainActivity.getApplicationContext()
/******** 下面一直返回null ***********/
let mBluetoothGatt = bluetoothDevice.connectGatt(context, false, mBluetoothGattCallback)
查看Android文档上设置Phy和设置Mtu是差不多的,而且uni已经提供了设置Mtu的api,是不是可以加上设置Phy的api了
