适用于Zebra RW420打印机的Android打印应用程序

适用于Zebra RW420打印机的Android打印应用程序,android,printing,bluetooth,zebra-printers,Android,Printing,Bluetooth,Zebra Printers,我打算开始开发一个简单的android应用程序,使用zebra RW420打印机打印标签。他们有android的SDK,但我不知道从哪里开始 I invision是一个只有一个屏幕的应用程序,它要求提供标签或采购订单、我们要打印多少份以及一个打印按钮。有人能帮我开始吗。任何帮助都将不胜感激 我将如何搜索打印机SDK会为我做吗??或者我必须使用Androids BluetoothAdapter类。。。关于标签格式,我必须自己创建还是可以使用SDK中的现有文件 我可以将打印机设置为打印多份副本吗?S

我打算开始开发一个简单的android应用程序,使用zebra RW420打印机打印标签。他们有android的SDK,但我不知道从哪里开始

I invision是一个只有一个屏幕的应用程序,它要求提供标签或采购订单、我们要打印多少份以及一个打印按钮。有人能帮我开始吗。任何帮助都将不胜感激

我将如何搜索打印机SDK会为我做吗??或者我必须使用Androids BluetoothAdapter类。。。关于标签格式,我必须自己创建还是可以使用SDK中的现有文件


我可以将打印机设置为打印多份副本吗?

SDK提供蓝牙发现类。查看文档和示例。查看
BluetoothDiscoverer
课程。它提供了一种查找所有蓝牙设备的方法,并在处理程序中通知您。SDK附带了一个开发人员演示,其中有一个如何进行发现的示例:

    try {
        BluetoothDiscoverer.findPrinters(this, new DiscoveryHandler() {

            public void foundPrinter(DiscoveredPrinter printer) {
                String macAddress = printer.address;
                //I found a printer! I can use the properties of a Discovered printer (address) to make a Bluetooth Connection
            }

            public void discoveryFinished() {
                //Discovery is done
            }

            public void discoveryError(String message) {
                //Error during discovery
            }
        });
    } catch (ConnectionException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
1) 您必须从以下线程打印:

new Thread (new Runnable () {
  public void run () {
    enablePrintButton (false);
    Looper.prepare ();
    doConnectionTest ();
    Looper.loop ();
    Looper.myLooper ().quit ();
  }
}).start ();
2) 然后:

3) 打印方法:

private void sendTestLabel () {
    try {
      ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.createLinkOsPrinter (printer);

      PrinterStatus printerStatus =
          (linkOsPrinter != null) ? linkOsPrinter.getCurrentStatus () : printer.getCurrentStatus ();

      if (printerStatus.isReadyToPrint) {
        byte[] configLabel = getConfigLabel ();
        connection.write (configLabel);
        setStatus ("Sending Data", Color.BLUE);
      } else if (printerStatus.isHeadOpen) {
        setStatus ("Printer Head Open", Color.RED);
      } else if (printerStatus.isPaused) {
        setStatus ("Printer is Paused", Color.RED);
      } else if (printerStatus.isPaperOut) {
        setStatus ("Printer Media Out", Color.RED);
      }
      DemoSleeper.sleep (1500);
      if (connection instanceof BluetoothConnection) {
        String friendlyName = ((BluetoothConnection) connection).getFriendlyName ();
        setStatus (friendlyName, Color.MAGENTA);
        DemoSleeper.sleep (500);
      }
    } catch (ConnectionException e) {
      setStatus (e.getMessage (), Color.RED);
    } finally {
      disconnect ();
    }
  }
4)标签配置方法:

private byte[] getConfigLabel () {
     byte[] configLabel = null;

     try {
       PrinterLanguage printerLanguage = printer.getPrinterControlLanguage ();
       SGD.SET ("device.languages", "zpl", connection);

       if (printerLanguage == PrinterLanguage.ZPL) {
         configLabel = "^XA^FO17,16^GB379,371,8^FS^FT65,255^A0N,135,134^FDTEST^FS^XZ".getBytes();
       } else if (printerLanguage == PrinterLanguage.CPCL) {

         String msg = setPopratnica ();

         msg = format (msg);

         configLabel = msg.getBytes ("windows-1250");
       }
     } catch (Exception e) {
     }
     return configLabel;
   }
public ZebraPrinter connect () {
     setStatus ("Connecting...", Color.YELLOW);
     connection = null;
     connection = new BluetoothConnection (getBluetoothAddressKey ());
    try {
       connection.open ();
       setStatus ("Connected", Color.GREEN);
         } catch (ConnectionException e) {
           setStatus ("Comm Error! Disconnecting", Color.RED);
           DemoSleeper.sleep (1000);
           disconnect ();
         }

         ZebraPrinter printer = null;

         if (connection.isConnected ()) {
           try {
             printer = ZebraPrinterFactory.getInstance (connection);
             setStatus ("Determining Printer Language", Color.YELLOW);
             String pl = SGD.GET ("device.languages", connection);
             setStatus ("Printer Language " + pl, Color.BLUE);
          } catch (ConnectionException e) {
             setStatus ("Unknown Printer Language", Color.RED);
             printer = null;
             DemoSleeper.sleep (1000);
             disconnect ();
           } catch (ZebraPrinterLanguageUnknownException e) {
             setStatus ("Unknown Printer Language", Color.RED);
             printer = null;
             DemoSleeper.sleep (1000);
             disconnect ();
           }
         }
         return printer;
}
public void disconnect () {
    try {
      setStatus ("Disconnecting", Color.RED);
      if (connection != null) {
        connection.close ();
      }
      setStatus ("Not Connected", Color.RED);
    } catch (ConnectionException e) {
      setStatus ("COMM Error! Disconnected", Color.RED);
    } finally {
      enablePrintButton (true);
    }
  }
5)连接方式:

private byte[] getConfigLabel () {
     byte[] configLabel = null;

     try {
       PrinterLanguage printerLanguage = printer.getPrinterControlLanguage ();
       SGD.SET ("device.languages", "zpl", connection);

       if (printerLanguage == PrinterLanguage.ZPL) {
         configLabel = "^XA^FO17,16^GB379,371,8^FS^FT65,255^A0N,135,134^FDTEST^FS^XZ".getBytes();
       } else if (printerLanguage == PrinterLanguage.CPCL) {

         String msg = setPopratnica ();

         msg = format (msg);

         configLabel = msg.getBytes ("windows-1250");
       }
     } catch (Exception e) {
     }
     return configLabel;
   }
public ZebraPrinter connect () {
     setStatus ("Connecting...", Color.YELLOW);
     connection = null;
     connection = new BluetoothConnection (getBluetoothAddressKey ());
    try {
       connection.open ();
       setStatus ("Connected", Color.GREEN);
         } catch (ConnectionException e) {
           setStatus ("Comm Error! Disconnecting", Color.RED);
           DemoSleeper.sleep (1000);
           disconnect ();
         }

         ZebraPrinter printer = null;

         if (connection.isConnected ()) {
           try {
             printer = ZebraPrinterFactory.getInstance (connection);
             setStatus ("Determining Printer Language", Color.YELLOW);
             String pl = SGD.GET ("device.languages", connection);
             setStatus ("Printer Language " + pl, Color.BLUE);
          } catch (ConnectionException e) {
             setStatus ("Unknown Printer Language", Color.RED);
             printer = null;
             DemoSleeper.sleep (1000);
             disconnect ();
           } catch (ZebraPrinterLanguageUnknownException e) {
             setStatus ("Unknown Printer Language", Color.RED);
             printer = null;
             DemoSleeper.sleep (1000);
             disconnect ();
           }
         }
         return printer;
}
public void disconnect () {
    try {
      setStatus ("Disconnecting", Color.RED);
      if (connection != null) {
        connection.close ();
      }
      setStatus ("Not Connected", Color.RED);
    } catch (ConnectionException e) {
      setStatus ("COMM Error! Disconnected", Color.RED);
    } finally {
      enablePrintButton (true);
    }
  }
6)断开方法:

private byte[] getConfigLabel () {
     byte[] configLabel = null;

     try {
       PrinterLanguage printerLanguage = printer.getPrinterControlLanguage ();
       SGD.SET ("device.languages", "zpl", connection);

       if (printerLanguage == PrinterLanguage.ZPL) {
         configLabel = "^XA^FO17,16^GB379,371,8^FS^FT65,255^A0N,135,134^FDTEST^FS^XZ".getBytes();
       } else if (printerLanguage == PrinterLanguage.CPCL) {

         String msg = setPopratnica ();

         msg = format (msg);

         configLabel = msg.getBytes ("windows-1250");
       }
     } catch (Exception e) {
     }
     return configLabel;
   }
public ZebraPrinter connect () {
     setStatus ("Connecting...", Color.YELLOW);
     connection = null;
     connection = new BluetoothConnection (getBluetoothAddressKey ());
    try {
       connection.open ();
       setStatus ("Connected", Color.GREEN);
         } catch (ConnectionException e) {
           setStatus ("Comm Error! Disconnecting", Color.RED);
           DemoSleeper.sleep (1000);
           disconnect ();
         }

         ZebraPrinter printer = null;

         if (connection.isConnected ()) {
           try {
             printer = ZebraPrinterFactory.getInstance (connection);
             setStatus ("Determining Printer Language", Color.YELLOW);
             String pl = SGD.GET ("device.languages", connection);
             setStatus ("Printer Language " + pl, Color.BLUE);
          } catch (ConnectionException e) {
             setStatus ("Unknown Printer Language", Color.RED);
             printer = null;
             DemoSleeper.sleep (1000);
             disconnect ();
           } catch (ZebraPrinterLanguageUnknownException e) {
             setStatus ("Unknown Printer Language", Color.RED);
             printer = null;
             DemoSleeper.sleep (1000);
             disconnect ();
           }
         }
         return printer;
}
public void disconnect () {
    try {
      setStatus ("Disconnecting", Color.RED);
      if (connection != null) {
        connection.close ();
      }
      setStatus ("Not Connected", Color.RED);
    } catch (ConnectionException e) {
      setStatus ("COMM Error! Disconnected", Color.RED);
    } finally {
      enablePrintButton (true);
    }
  }
此外,您还必须有卧铺课程:

public class DemoSleeper {
    private DemoSleeper () {
    }

    public static void sleep(int ms) {
        try {
            Thread.sleep(ms);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

@Ovi,我们已经有一个斑马打印机的低流量标签,我们不需要进一步划分。考虑到爆炸事件的复杂性,知识越集中越好;这是有道理的。谢谢你的解释!它对你有用吗?我想在我的qln420 zebra模型中打印pdf,已经按照他们的建议购买了虚拟pdf。