Skip to content

Commit

Permalink
Merge pull request #318 from yoviep/ISSUE_284
Browse files Browse the repository at this point in the history
Fix issue #284
  • Loading branch information
DantSu authored Aug 24, 2022
2 parents aaf8d6a + 8cb56e5 commit 6b0b67d
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public BluetoothConnection connect() throws EscPosConnectionException {
}

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
ParcelUuid[] uuids = this.device.getUuids();
UUID uuid = (uuids != null && uuids.length > 0) ? uuids[0].getUuid() : UUID.randomUUID();

UUID uuid = this.getDeviceUUID();

try {
this.socket = this.device.createRfcommSocketToServiceRecord(uuid);
Expand All @@ -77,6 +77,15 @@ public BluetoothConnection connect() throws EscPosConnectionException {
return this;
}

/**
* Get bluetooth device UUID
*/
protected UUID getDeviceUUID() {
// https://developer.android.com/reference/android/bluetooth/BluetoothDevice - "00001101-0000-1000-8000-00805f9b34fb" SPP UUID
ParcelUuid[] uuids = device.getUuids();
return (uuids != null && uuids.length > 0) ? uuids[0].getUuid() : UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
}

/**
* Close the socket connection with the bluetooth device.
*/
Expand Down

0 comments on commit 6b0b67d

Please sign in to comment.