diff --git a/android/src/main/java/io/github/edufolly/flutterbluetoothserial/BluetoothConnection.java b/android/src/main/java/io/github/edufolly/flutterbluetoothserial/BluetoothConnection.java index c3b20ee7..e4826ac0 100644 --- a/android/src/main/java/io/github/edufolly/flutterbluetoothserial/BluetoothConnection.java +++ b/android/src/main/java/io/github/edufolly/flutterbluetoothserial/BluetoothConnection.java @@ -36,6 +36,7 @@ public BluetoothConnection(BluetoothAdapter bluetoothAdapter) { // @TODO . `connect` other methods than `createRfcommSocketToServiceRecord`, including hidden one raw `createRfcommSocket` (on channel). // @TODO ? how about turning it into factoried? /// Connects to given device by hardware address + public void connect(String address, UUID uuid) throws IOException { if (isConnected()) { throw new IOException("already connected"); @@ -61,8 +62,11 @@ public void connect(String address, UUID uuid) throws IOException { } /// Connects to given device by hardware address (default UUID used) public void connect(String address) throws IOException { - connect(address, DEFAULT_UUID); - } + BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); + BluetoothDevice device = btAdapter.getRemoteDevice(address); + ParcelUuid[] uuids = (ParcelUuid[]) device.getUuids(); + connect(address, uuids[0].getUuid()); + } /// Disconnects current session (ignore if not connected) public void disconnect() {