Android 如何通过蓝牙与zebra mz320打印机配对?
我正在实现一个应用程序 根据我的要求,我想通过移动蓝牙从zebra mz320打印机获取打印输出 我正在尝试从Android 如何通过蓝牙与zebra mz320打印机配对?,android,bluetooth,Android,Bluetooth,我正在实现一个应用程序 根据我的要求,我想通过移动蓝牙从zebra mz320打印机获取打印输出 我正在尝试从移动蓝牙到打印机蓝牙配对。 当我尝试配对时,打印机会抛出一条消息,如“键入1234或0000 PIN for make” 连接 我输入了相同的密码 但打印机未与我的移动设备配对 它抛出一个异常,如com.zebra.android.comm.ZebraPrinterConnectionException:无法连接到打印机:无法启动服务发现 如果有人知道解决方案,请帮助我。 提前感谢。UU
移动蓝牙
到打印机蓝牙配对。
当我尝试配对时,打印机会抛出一条消息,如“键入1234或0000 PIN for make”
连接
我输入了相同的密码
但打印机未与我的移动设备配对
它抛出一个异常,如com.zebra.android.comm.ZebraPrinterConnectionException:无法连接到打印机:无法启动服务发现
如果有人知道解决方案,请帮助我。提前感谢。UUIDs列表请参阅。 您应该尝试队列中此代码段中的一个或所有代码段以建立连接: @TargetApi(10)专用BluetoothSocket连接设备UsingAPI10()引发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;
}
BluetoothSocket=null;
IOException ioex=null;
int port=1;//如果我不感到困惑的话,可能是从1到14
UUID SPP_UUID=UUID.fromString(“00001101-0000-1000-8000-00805F9B34FB”);
//方式#0.使用Android<2.3的解决方案连接
试一试{
如果(!isThreadActive)
返回null;
Log.d(“通过API10尝试:CreateSecurerCommsocketToServiceRecord”);
socket=mDevice.createInsurerFComSocketToServiceRecord(SPP_UUID);//或RFCOMM_UUID);
}catch(IOException e){ioex=e;}
if(套接字!=null&&ioex==null){
试一试{
socket.connect();
setStreams(socket.getOutputStream(),socket.getInputStream());
}捕获(IOEX异常){
ioex=ex;
试一试{
socket.close();
}捕获(IOE异常){
}最后{
socket=null;
}
}
}
if(套接字!=null&&ioex==null){
返回插座;
}
ioex=null;
socket=null;
//方式#1.通过UUID使用标准安全连接程序
试一试{
如果(!isThreadActive)
返回null;
Log.d(“通过API10:createRfcommSocketToServiceRecord尝试”);
socket=mDevice
.createRfcommSocketToServiceRecord(SPP_UUID);//或RFCOMM_UUID
}捕获(IOE异常){
ioex=e;
}
if(套接字!=null&&ioex==null){
试一试{
socket.connect();
setStreams(socket.getOutputStream(),socket.getInputStream());
}捕获(IOEX异常){
ioex=ex;
试一试{
socket.close();
}捕获(IOE异常){
}最后{
socket=null;
}
}
}
if(套接字!=null&&ioex==null){
返回插座;
}
//方法#2.使用不安全套接字的隐藏api过程
socket=null;
ioex=null;
//尝试退回到API5方法
试一试{
如果(!isThreadActive)
返回null;
Log.d(“通过API10:CreateSecurerCommSocket尝试”);
方法m=mDevice.getClass().getMethod(
“CreateSecurerCommSocket”,新类[]{int.Class});
套接字=(BluetoothSocket)m.invoke(mDevice,Integer.valueOf(port));
}捕获(IOE){/…}
if(套接字!=null&&ioex==null){
试一试{
socket.connect();
setStreams(socket.getOutputStream(),socket.getInputStream());
}捕获(IOEX异常){
ioex=ex;
试一试{
socket.close();
}捕获(IOE异常){
}最后{
socket=null;
}
}
}
if(套接字!=null&&ioex==null){
返回插座;
}
ioex=null;
socket=null;
//方式#3.使用Android<2.3的解决方案连接
试一试{
如果(!isThreadActive)
返回null;
Log.d(“通过API10:createRfcommSocket尝试”);
方法m=mDevice.getClass().getMethod(“createRfcommSocket”,
新类[]{int.Class});
套接字=(BluetoothSocket)m.invoke(mDevice,Integer.valueOf(port));
}捕获(IOE异常){
ioex=e;
}
if(套接字!=null&&ioex==null){
试一试{
socket.connect();
setStreams(socket.getOutputStream(),socket.getInputStream());
}捕获(IOEX异常){
ioex=ex;
试一试{
socket.close();
}捕获(IOE异常){
}最后{
socket=null;
}
}
}
if(套接字!=null&&ioex==null){
返回插座;
}
返回插座;
}
我也有同样的问题。您找到解决方案了吗?您需要获取打印机的UUID。listenUsingRfcommWithServiceRecord(字符串名称,UUID UUID)