2013-11-26 52 views
0

我想要做的是用zebra mz220打印標籤,使用我的SQLite數據庫中的信息,但是我不知道如何使用字符串填充標籤。這是到目前爲止我的代碼從Android打印斑馬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; 

請幫忙,謝謝

+0

歡迎#1。你到目前爲止嘗試了什麼?我知道你是新人,但要記住,你的一些研究可以幫助你解決問題。你到目前爲止嘗試過什麼嗎?請先顯示你的努力,以便其他人可以幫助你。此外,請閱讀[常見問題](http://stackoverflow.com/help)和[如何問](http://stackoverflow.com/questions/how-to-ask) – kgdesouz

回答

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

+0

你好,謝謝你的回答。我已經閱讀過cpcl手冊,我會嘗試更好地解釋我的自我,在我的前兩個活動中是收集信息,然後將它發送到sqlite數據庫,這些信息我想打印票據,任何想法? 。謝謝你的幫助 –