一米阳光2015
一米阳光2015
  • 发布:2017-05-19 17:27
  • 更新:2018-09-05 10:11
  • 阅读:4812

谁做过用mui 进行蓝牙 传输文件?

分类:HTML5+
main = 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(mac_address);  
                plus.android.importClass(device);  
                bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid);  
                plus.android.importClass(bluetoothSocket);  

                if(!bluetoothSocket.isConnected()) {  
                    console.log('检测到设备未连接,尝试连接....');  
                    bluetoothSocket.connect();  
                }  
                if(bluetoothSocket.isConnected()) {  

                    console.log('设备已连接');  
                    var outputStream = bluetoothSocket.getOutputStream();  
                    plus.android.importClass(outputStream);  
                    var string = "传输测试\r\n";  
                    var bytes = plus.android.invoke(string, 'getBytes', 'gbk');  
                    outputStream.write(bytes);  
                    outputStream.flush();  
                    device = null //这里关键  
                    bluetoothSocket.close(); //必须关闭蓝牙连接否则意外断开的话打印错误  

                } else {  
                    console.log('设备连接失败');  
                }

在执行bluetoothSocket.connect();的时候报错,但是我已经打开了对面的蓝牙, 也做好了接收文件的准备

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

2017-05-19 17:27 负责人:无 分享
已邀请:
小猪熊

小猪熊

LZ解决了吗 我也遇到了

喜洋洋liugp

喜洋洋liugp

连接必须要保证uuid一致 如果连接的是手机设备的话可能的写一个服务端  去接受连接

8***@qq.com

8***@qq.com

最近研究蓝牙打印,也遇到这个问题,不知道有没有解决办法。哪位大神解决了,寻求帮助!

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