1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-23 00:33:09 +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,16 +476,21 @@ 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() {
@Override
public void run() {
if (leScanCallback != null) {
stopLeScan(); stopLeScan();
connectGatt(device); connectGatt(device);
} }
} }
});
}
}; };
Timber.d("Starting LE scan for device [%s]", hwAddress); Timber.d("Starting LE scan for device [%s]", hwAddress);