@Override public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bytes) { Log.d(TAG, "discovered device: " + bluetoothDevice.getName()); Log.d(TAG, "device MAC: " + bluetoothDevice.getAddress()); Home home = ((Alexandra) getApplicationContext()).getHome(); if (home != null) { for (Gadget gadget : home.getGadgets()) { Log.d(TAG, "gadget MAC: " + gadget.getMAC()); if (gadget.getMAC().equals(bluetoothDevice.getAddress())) { Log.d(TAG, "trying to connect GATT"); gadget.setBluetoothGatt( bluetoothDevice.connectGatt( getApplicationContext(), true, gadget.getBluetoothGattCallback())); } } } }