Bond a Low Energy device on Android
-
wrote on 9 Jul 2019, 14:00 last edited by Darude 0 7 Sept 2019, 14:45
Hi, I'm trying to bond a ble device. I already did this in the past calling QBluetoothLocalDevice::requestPairing, I don't know if this is exactly the right way to do it, but it works with 5.9.
Now I need to do this operation with QT > 5.12, but this method seems don't work properly. When I call requestPairing method the QBluetoothLocalDevice::PairingError signal occurs immediately. However the OS panel to pair the device is shown but connection is closed and operation is aborted, so no pairing is possible.
Is my pairing procedure correct? Is there some other way to do it? Is it a bug? -
Hi, I'm trying to bond a ble device. I already did this in the past calling QBluetoothLocalDevice::requestPairing, I don't know if this is exactly the right way to do it, but it works with 5.9.
Now I need to do this operation with QT > 5.12, but this method seems don't work properly. When I call requestPairing method the QBluetoothLocalDevice::PairingError signal occurs immediately. However the OS panel to pair the device is shown but connection is closed and operation is aborted, so no pairing is possible.
Is my pairing procedure correct? Is there some other way to do it? Is it a bug?wrote on 9 Jul 2019, 15:45 last edited by@Darude-0 said in Bond a Low Energy device on Android:
Is my pairing procedure correct?
What is your procedure ? Can you show the code ?
Did you add permissions for Bluetooth in the Android manifest ?
<uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
-
wrote on 10 Jul 2019, 08:51 last edited by
Yes, these permissions are included in manifest. I run same code with QT 5.9.8 and works well.
Here my code, where "target" is a QBluetoothDeviceInfo* from a list of devices discovered by QBluetoothDeviceDiscoveryAgentbleController = new QLowEnergyController(*target); myAdapter = new QBluetoothLocalDevice(); if (myAdapter->pairingStatus(target->address()) != QBluetoothLocalDevice::Paired) { connect(myAdapter,SIGNAL(error(QBluetoothLocalDevice::Error)), this,SLOT(pairingError(QBluetoothLocalDevice::Error))); connect(myAdapter,SIGNAL(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing)), this,SLOT(pairingSuccess(QBluetoothAddress,QBluetoothLocalDevice::Pairing))); connect(myAdapter,SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)), this, SLOT(modeStateChanged(QBluetoothLocalDevice::HostMode))); myAdapter->requestPairing(target->address(),QBluetoothLocalDevice::Paired); } else { bleController->connectToDevice(); }
-
Yes, these permissions are included in manifest. I run same code with QT 5.9.8 and works well.
Here my code, where "target" is a QBluetoothDeviceInfo* from a list of devices discovered by QBluetoothDeviceDiscoveryAgentbleController = new QLowEnergyController(*target); myAdapter = new QBluetoothLocalDevice(); if (myAdapter->pairingStatus(target->address()) != QBluetoothLocalDevice::Paired) { connect(myAdapter,SIGNAL(error(QBluetoothLocalDevice::Error)), this,SLOT(pairingError(QBluetoothLocalDevice::Error))); connect(myAdapter,SIGNAL(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing)), this,SLOT(pairingSuccess(QBluetoothAddress,QBluetoothLocalDevice::Pairing))); connect(myAdapter,SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)), this, SLOT(modeStateChanged(QBluetoothLocalDevice::HostMode))); myAdapter->requestPairing(target->address(),QBluetoothLocalDevice::Paired); } else { bleController->connectToDevice(); }
-
wrote on 10 Jul 2019, 11:27 last edited by
In my opinion too. I'll try to open an issue
-
wrote on 3 Sept 2020, 17:31 last edited by
Hello Darude!
Did you resolve this problem?
I have same it now. -
wrote on 4 Sept 2020, 08:46 last edited by
@ivk16 Yes, take a look here: https://bugreports.qt.io/browse/QTBUG-76565