@Override public void disconnect(BtDevice btDevice) { BtContainer btContainer = AppProvider.getBtContainer(); BluetoothSocket socket = btContainer.getSocketForDevice(btDevice); if (socket != null) { try { InputStream is = socket.getInputStream(); OutputStream os = socket.getOutputStream(); if (is != null) { is.close(); } if (os != null) { os.close(); } socket.close(); } catch (IOException e) { btControllerInterface.disconnectFailed(btDevice); } } btContainer.removeConnected(btDevice); btControllerInterface.updateConnectedList(); }
@Override public void discoverDevices() { bluetoothAdapter.cancelDiscovery(); IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); BtBroadcastReceiver receiver = AppProvider.getBtFactory().createBtBroadcastReceiver(btControllerInterface); btControllerInterface.registerBtReceiver(receiver, filter); bluetoothAdapter.startDiscovery(); }