Zebra RW220无法在多个设备上打印

时间:2014-11-26 11:50:54

标签: android bluetooth zebra-printers

我正在开发一些必须通过蓝牙Zebra打印机打印的Android应用程序,在几个设备上出现这个例外:

11-26 12:37:00.399: W/System.err(17850): com.zebra.sdk.comm.ConnectionException: Could not connect to device: [JSR82] connect: Connection is not created (failed or aborted).
11-26 12:37:00.400: W/System.err(17850):    at com.zebra.sdk.comm.ConnectionA.open(Unknown Source)
11-26 12:37:00.401: W/System.err(17850):    at com.zebra.sdk.comm.BluetoothConnection.open(Unknown Source)
11-26 12:37:00.403: W/System.err(17850):    at hr.ipc.ipcprinttest.Main$2.run(Main.java:104)
11-26 12:37:00.404: W/System.err(17850):    at java.lang.Thread.run(Thread.java:838)

以下是我使用的代码示例:

public class Main extends Activity {

    String theBtMacAddress = "00:03:7A:67:EE:08";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void onClick(View v){
        switch (v.getId()) {
        case R.id.button1:
            sendCpclOverBluetooth(theBtMacAddress);
            break;
        }
    }

    private void sendCpclOverBluetooth(final String theBtMacAddress) {

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

                    Connection thePrinterConn = new BluetoothConnectionInsecure(theBtMacAddress);

                    Looper.prepare();

                    thePrinterConn.open();


                    String cpclData = "! 0 200 200 260 1\r\n"
                            + "TONE 0"
                            + "SPEED 3\r\n"
                            + "PREFEED 0\r\n"  
                            + "TEXT 11 0 0 0   ***Print test***\r\n"
                            + "LINE 0 33 350 33 3\r\n"
                            + "TEXT 11 0 0 48   Baterija: -1%\r\n"
                            + "TEXT 11 0 0 76   Datum: 26. studenoga 2014 09:07:34\r\n"
                            + "TEXT 11 0 0 104   Model ure|aja: Lenovo Lenovo A5500-HV\r\n"
                            + "TEXT 11 0 0 132   abc_^]Đ[@_~}|`{\r\n"
                            + "TEXT 11 0 0 160   ***Print test***\r\n"
                            + "PRINT\r\n";

                    thePrinterConn.write(cpclData.getBytes());

                    Thread.sleep(500);

                    thePrinterConn.close();

                    Looper.myLooper().quit();

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}

我已经尝试了一切,但仍然没有找到具体的解决方案。如果有任何解决这个问题的方法,我会请你帮助我。 谢谢你,最诚挚的问候!

1 个答案:

答案 0 :(得分:0)

在android设备上,斑马SDK返回错误我使用此代码:

synchronized private static void zebraPrint() throws IOException {
    BluetoothAdapter blueTooth = BluetoothAdapter.getDefaultAdapter();
    blueTooth.cancelDiscovery();
    UUID SERIAL_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
    if (!blueTooth.isEnabled())
        blueTooth.enable();
    BluetoothDevice blueDevice = blueTooth.getRemoteDevice(printerMac);

    BluetoothSocket bSocket = blueDevice.createInsecureRfcommSocketToServiceRecord(SERIAL_UUID);
    if (!bSocket.isConnected())
        bSocket.connect();
    OutputStream  out = bSocket.getOutputStream();
    String data = "Your cpcl data";
    out.write(text.getBytes());
    out.flush();
    bSocket.close(); }