How to make a pair via bluetooth for zebra mz320 printter?

I use one application.

According to my requirement, I want to print using the zebra mz320 printer via mobile bluetooth.

I am trying to pair from mobile bluetooth to printer bluetoth.

When I try to pair, the printer displays a message such as "Type 1234 or 0000 PIN for make connection.

I dialed the same PIN.

But the printer is not paired with my mobile device.

It throws an exception like com.zebra.android.comm.ZebraPrinterConnectionException: Could not connect to printer: Unable to start Service Discovery

If anyone knows a solution, please help me.
Thanks in advance.

+7
source share
1 answer

For a list of UUIDs, see here . You must try one or all of these fragments in the queue to establish a connection:

@TargetApi (10) private BluetoothSocket connectDeviceUsingAPI10 () throws an 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; } 
+1
source

All Articles