2013-11-26 117 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数据库,这些信息我想打印票据,任何想法? 。谢谢你的帮助 –