用android从斑马MZ220打印

时间:2013-11-26 18:26:47

标签: android

我要做的是使用我在SQLite数据库中的信息打印带有zebra mz220的标签,但我不知道如何使用字符串填写标签。这是我到目前为止的代码


案例R.id.bprint:

        new Thread(new Runnable() {
            public void run() {
                try {

                    // Instantiate connection for given Bluetooth® MAC Address.
                    ZebraPrinterConnection thePrinterConn = new BluetoothPrinterConnection("00:22:58:3C:9F:0B");

                    // Initialize 
                    Looper.prepare();

                    // Open the connection - physical connection is established here.
                    thePrinterConn.open();



                    // here it should fill in the label but it doesn't =(
                    thePrinterConn.write("Input (ENCODING.LBL):! 0 200 200 200 1 ENCODING UTF-8 TEXT 0 20 30 r/n/ PRINTr/n/".getBytes());



                    //Make sure the data got to the printer before closing the connection
                    Thread.sleep(500);

                    // Close the connection to release resources.
                    thePrinterConn.close();

                    Looper.myLooper().quit();

                } catch (Exception e) {
                    // Handle communications error here
                    e.printStackTrace();
                }
            }
            }).start();

            break;

    case R.id.spb:

        startActivity(new Intent(this, Barcode.class));

        break;

请帮忙,谢谢

1 个答案:

答案 0 :(得分:1)

代码看起来合适,但不幸的是你的评论“我不知道如何使用字符串填写标签”不是很清楚。运行代码时的结果是什么?你想要实现什么目标?例如,您可以在“写入”调用中将以下数据发送到打印机。假设您的打印机处于CPCL模式:

thePrinterConn.write("! 0 200 200 210 1\r\nTEXT 4 0 30 30 Hello world\r\nFORM\r\nPRINT\r\n" .getBytes()); 

CPCL手册第2页第3页:support.zebra.com/cpws/docs/comtec/PROMAN-CPCL_RevY.pdf