Android蓝牙打印机面临一个奇怪的问题。首次尝试连接打印机设备时,我遇到以下问题
BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
java.io.IOException: read failed, socket might closed or timeout, read ret: -1
at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:738)
at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:750)
at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:375)
我正在使用以下代码将设备与打印机连接
Thread connectThread = new Thread(new Runnable() {
@Override
public void run() {
try {
boolean gotuuid = btDevices.getItem(position)
.fetchUuidsWithSdp();
UUID uuid = btDevices.getItem(position).getUuids()[0]
.getUuid();
mbtSocket = btDevices.getItem(position)
.createRfcommSocketToServiceRecord(uuid);
mbtSocket.connect();
} catch (IOException ex) {
ex.printStackTrace();
runOnUiThread(socketErrorRunnable);
try {
mbtSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
mbtSocket = null;
} finally {
runOnUiThread(new Runnable() {
@Override
public void run() {
finish();
}
});
}
}
});
connectThread.start();
注意:一旦我尝试调试上述代码块,它将与打印机连接并能够打印。只是正常模式下的问题。
任何人都有相同问题的想法。
答案 0 :(得分:0)
仅供参考
我使用以下代码进行打印机集成,但没有出现此问题。 https://amsheer007.wordpress.com/2019/04/12/bluetooth-printer-for-android/