Skip to content

Commit

Permalink
Added a fallback connection option for newer Android, recommended by @…
Browse files Browse the repository at this point in the history
  • Loading branch information
Erhannis committed Jan 16, 2024
1 parent 0dba3fd commit d36b2f5
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ public void connect(String address, UUID uuid) throws IOException {
// Cancel discovery, even though we didn't start it
bluetoothAdapter.cancelDiscovery();

socket.connect();
try {
socket.connect();
} catch (IOException e) {
try {
// Newer versions of android may require voodoo; see https://stackoverflow.com/a/25647197
socket = (BluetoothSocket) device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}).invoke(device,1);
socket.connect();
} catch (Exception e2) {
throw new IOException("Failed to connect", e2);
}
}

connectionThread = new ConnectionThread(socket);
connectionThread.start();
Expand Down

0 comments on commit d36b2f5

Please sign in to comment.