Skip to content

Commit 6b0b67d

Browse files
authored
Merge pull request #318 from yoviep/ISSUE_284
Fix issue #284
2 parents aaf8d6a + 8cb56e5 commit 6b0b67d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

escposprinter/src/main/java/com/dantsu/escposprinter/connection/bluetooth/BluetoothConnection.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public BluetoothConnection connect() throws EscPosConnectionException {
6060
}
6161

6262
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
63-
ParcelUuid[] uuids = this.device.getUuids();
64-
UUID uuid = (uuids != null && uuids.length > 0) ? uuids[0].getUuid() : UUID.randomUUID();
63+
64+
UUID uuid = this.getDeviceUUID();
6565

6666
try {
6767
this.socket = this.device.createRfcommSocketToServiceRecord(uuid);
@@ -77,6 +77,15 @@ public BluetoothConnection connect() throws EscPosConnectionException {
7777
return this;
7878
}
7979

80+
/**
81+
* Get bluetooth device UUID
82+
*/
83+
protected UUID getDeviceUUID() {
84+
// https://developer.android.com/reference/android/bluetooth/BluetoothDevice - "00001101-0000-1000-8000-00805f9b34fb" SPP UUID
85+
ParcelUuid[] uuids = device.getUuids();
86+
return (uuids != null && uuids.length > 0) ? uuids[0].getUuid() : UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
87+
}
88+
8089
/**
8190
* Close the socket connection with the bluetooth device.
8291
*/

0 commit comments

Comments
 (0)