【问题标题】:How to make pair through bluetooth to zebra mz320 printter?如何通过蓝牙与斑马mz320打印机配对?
【发布时间】:2012-12-13 12:22:49
【问题描述】:

我正在实现一个应用程序。

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

我正在尝试从mobile bluetooth 到printer bluetoth. 制作一对

当我尝试配对时,打印机会抛出类似“键入 1234 或 0000 PIN for make 连接。

我输入了相同的 PIN。

但打印机未与我的移动设备配对。

它会抛出类似com.zebra.android.comm.ZebraPrinterConnectionException: Could not connect to printer: Unable to start Service Discovery的异常

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

【问题讨论】:

  • 我也有同样的问题。你找到解决办法了吗?
  • 需要获取打印机的UUID。 listenUsingRfcommWithServiceRecord(字符串名称,UUID uuid)

标签: android bluetooth


【解决方案1】:

UUID 列表见here。 您应该尝试从队列中的这个 sn-ps 中的一个或全部来建立连接:

@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;
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-28
    • 2014-08-25
    • 2013-12-24
    • 2014-04-26
    • 2014-07-22
    • 2016-06-23
    • 1970-01-01
    相关资源
    最近更新 更多