Zebra RW220 not print on several devices

872 Views Asked by At

I'm developing some android application which must print via bluetooth Zebra printer and on several devices appears to me this exception:

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)

Here is an example of code which I use:

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();
    }
}

I've tried everything and still have not managed to find a concrete solution. If there is when any solution to this problem I would ask you to help me. Thank you and best regards!

1

There are 1 best solutions below

0
On

On android device where zebra SDK return error i use this code:

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(); }