如何通过蓝牙与斑马mz320打印机配对?

kir*_*ran 7 android bluetooth

我正在实施一个应用程序.

根据我的要求,我想通过移动蓝牙从斑马mz320打印机打印出来.

我试图让一对从mobile bluetoothprinter bluetoth.

当我尝试配对时,打印机会抛出类似"1234或0000 PIN类型"的消息进行连接.

我键入了相同的PIN码.

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

它抛出了一个例外 com.zebra.android.comm.ZebraPrinterConnectionException: Could not connect to printer: Unable to start Service Discovery

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

Ras*_*las 1

UUID 列表请参见此处。您应该尝试队列中此片段中的一个或全部来建立连接:

@TargetApi(10) 私有BluetoothSocket connectDeviceUsingAPI10() 抛出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;
  }
Run Code Online (Sandbox Code Playgroud)