gpt4 book ai didi

android - 如何通过蓝牙与 zebra mz320 打印机配对?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:12:58 25 4
gpt4 key购买 nike

我正在实现一个应用。

根据我的要求,我想通过移动蓝牙从 zebra mz320 打印机 打印输出。

我正在尝试从移动蓝牙打印机蓝牙。

当我尝试配对时,打印机抛出一条消息,如“输入 1234 或 0000 PIN 码进行制造连接。

我输入了相同的 PIN。

但是打印机没有与我的移动设备配对。

它抛出一个异常,如 com.zebra.android.comm.ZebraPrinterConnectionException: Could not connect to printer: Unable to start Service Discovery

如果有人知道解决方案,请帮助我。
提前致谢。

最佳答案

UUID 列表参见 here .您应该在队列中尝试此 fragment 中的一个或所有 fragment 以建立连接:

@TargetApi(10) private BluetoothSocket connectDeviceUsingAPI10() throws IOException {

BluetoothSocket socket = null;
IOException ioex = null;
int port = 1; // may be from 1 to 14 if I'm not confused
UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

// way #0. Connect using workaround for Android < 2.3
try {
if (!isThreadActive)
return null;
Log.d("Try via API10: createInsecureRfcommSocketToServiceRecord");
socket = mDevice.createInsecureRfcommSocketToServiceRecord(SPP_UUID); // or RFCOMM_UUID);
} catch (IOException e) { ioex = e; }
if (socket != null && ioex == null) {
try {
socket.connect();
setStreams(socket.getOutputStream(), socket.getInputStream());
} catch (IOException ex) {
ioex = ex;
try {
socket.close();
} catch (IOException e) {
} finally {
socket = null;
}
}
}
if (socket != null && ioex == null) {
return socket;

}

ioex = null;
socket = null;
// way #1. Using standard secure connection procedure via UUID
try {
if (!isThreadActive)
return null;
Log.d("Try via API10: createRfcommSocketToServiceRecord");
socket = mDevice
.createRfcommSocketToServiceRecord(SPP_UUID);// or RFCOMM_UUID
} catch (IOException e) {
ioex = e;
}
if (socket != null && ioex == null) {
try {
socket.connect();
setStreams(socket.getOutputStream(), socket.getInputStream());
} catch (IOException ex) {
ioex = ex;
try {
socket.close();
} catch (IOException e) {
} finally {
socket = null;
}
}
}
if (socket != null && ioex == null) {
return socket;
}

// way #2. Using hidden api procedure with insecure socket
socket = null;
ioex = null;
// Try to fallback to API5 method
try {
if (!isThreadActive)
return null;
Log.d("Try via API10: createInsecureRfcommSocket");
Method m = mDevice.getClass().getMethod(
"createInsecureRfcommSocket", new Class[] { int.class });
socket = (BluetoothSocket) m.invoke(mDevice, Integer.valueOf(port));
} catch (IOException e) { // ... }
if (socket != null && ioex == null) {
try {
socket.connect();
setStreams(socket.getOutputStream(), socket.getInputStream());
} catch (IOException ex) {
ioex = ex;
try {
socket.close();
} catch (IOException e) {
} finally {
socket = null;
}
}
}

if (socket != null && ioex == null) {
return socket;
}

ioex = null;
socket = null;
// way #3. Connect using workaround for Android < 2.3
try {
if (!isThreadActive)
return null;
Log.d("Try via API10: createRfcommSocket");
Method m = mDevice.getClass().getMethod("createRfcommSocket",
new Class[] { int.class });
socket = (BluetoothSocket) m.invoke(mDevice, Integer.valueOf(port));
} catch (IOException e) {
ioex = e;
}
if (socket != null && ioex == null) {
try {
socket.connect();
setStreams(socket.getOutputStream(), socket.getInputStream());
} catch (IOException ex) {
ioex = ex;
try {
socket.close();
} catch (IOException e) {
} finally {
socket = null;
}
}
}
if (socket != null && ioex == null) {
return socket;
}
return socket;
}

关于android - 如何通过蓝牙与 zebra mz320 打印机配对?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13859786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com