1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-23 08:43:15 +02:00

Do gatt connect on main thread

This commit is contained in:
Erik Johansson
2018-10-07 09:24:37 +02:00
parent e6f0613c7a
commit f2197c9ca9

View File

@@ -476,15 +476,20 @@ public abstract class BluetoothCommunication {
private void startLeScanForDevice(final String hwAddress) { private void startLeScanForDevice(final String hwAddress) {
leScanCallback = new BluetoothAdapter.LeScanCallback() { leScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override @Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
Timber.d("Found LE device %s [%s]", device.getName(), device.getAddress()); Timber.d("Found LE device %s [%s]", device.getName(), device.getAddress());
if (!device.getAddress().equals(hwAddress)) { if (!device.getAddress().equals(hwAddress)) {
return; return;
} }
synchronized (lock) { handler.post(new Runnable() {
stopLeScan(); @Override
connectGatt(device); public void run() {
} if (leScanCallback != null) {
stopLeScan();
connectGatt(device);
}
}
});
} }
}; };