简体   繁体   中英

Printing with zebra MZ220 from android

What i´m trying to do is to print a label with zebra mz220 using the information I have in my SQLite database, but I don´t know how to fill in the label using strings. Here is my code so far


case 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;

please help, thanks

The code looks appropriate, but unfortunately your comment "I don't know how to fill in the label using strings" isn't very clear. What is the outcome when you run your code? What are you trying to achieve? As an example, you can send the following data to the printer in your 'write' call. Assuming your printer is in CPCL mode:

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

CPCL manual section 2 page 3: support.zebra.com/cpws/docs/comtec/PROMAN-CPCL_RevY.pdf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM