首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >斑马RW220无法在多个设备上打印

斑马RW220无法在多个设备上打印
EN

Stack Overflow用户
提问于 2014-11-26 19:50:54
回答 1查看 668关注 0票数 0

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

代码语言:javascript
复制
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)

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

代码语言:javascript
复制
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();
    }
}

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

EN

回答 1

Stack Overflow用户

发布于 2015-08-20 20:48:41

在android设备上,zebra SDK返回错误,我使用以下代码:

代码语言:javascript
复制
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(); }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27148439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档