c***@163.com
c***@163.com
  • 发布:2019-05-10 01:35
  • 更新:2019-07-04 10:06
  • 阅读:1238

蓝牙 多次打印报错

分类:HBuilderX

蓝牙 多次打印总是报错

Uncaught java.io.IOException: read failed, socket might closed or timeout, read ret: -1;at android.bluetooth.BluetoothSocket.connect at printer.html:1
也代码控制了 还是报错

window.ConnectPrinter = function(bleId) {  

        if (device == null) {  
            var plusMain = plus.android.runtimeMainActivity(),  
                BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"),  
                UUID = plus.android.importClass("java.util.UUID"),  
                uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"),  
                BAdapter = BluetoothAdapter.getDefaultAdapter(),  
                device = BAdapter.getRemoteDevice(bleId);  

            plus.android.importClass(device);  

            var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid);  
            plus.android.importClass(bluetoothSocket);  

            BAdapter.cancelDiscovery();  
        }  
        //      alert("取消搜索");  
        if (!bluetoothSocket.isConnected()) {  
            //          alert("链接")  
            bluetoothSocket.connect();  
            mui.toast('打印机已就绪,可正常打印!');  
        }  

        this.gotoPrint = function(byteStr, options) {  
            var outputStream = bluetoothSocket.getOutputStream();  
            plus.android.importClass(outputStream);  
            if (byteStr) {  
                var bytes = plus.android.invoke(byteStr, 'getBytes', 'gbk');  
                if (options) {  
                    mui.each(options, function(index, item) {  
                        outputStream.write(item)  
                    });  
                }  
                outputStream.write(bytes);  
                outputStream.flush();  
            } else {  
                if (options) {  
                    mui.each(options, function(index, item) {  
                        outputStream.write(item)  
                        outputStream.flush();  
                    });  
                }  
2019-05-10 01:35 负责人:无 分享
已邀请:
DCloud_Android_zl

DCloud_Android_zl

麻烦提供一下,在什么设备上能够复现?

  • c***@163.com (作者)

    基本上都会,没有用 device == null 判断 ,重复初始化都会报错

    Uncaught java.io.IOException: read failed, socket might closed or timeout, read ret: -1;at android.bluetooth.BluetoothSocket.connect at printer.html:1


    加了控制要好一点,有时候还是会

    2019-05-10 12:01

t***@163.com

t***@163.com

你好,问题解决了吗?

该问题目前已经被锁定, 无法添加新回复