print_bluetooth(mac_address){
let that=this
uni.hideLoading()
let UUID = plus.android.importClass("java.util.UUID");
let uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
let device = BAdapter.getRemoteDevice(mac_address);
plus.android.importClass(device);
let bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid);
plus.android.importClass(bluetoothSocket);
if (!bluetoothSocket.isConnected()) {
console.log('检测到设备未连接,尝试连接....');
bluetoothSocket.connect();
}
console.log('设备已连接');
if (bluetoothSocket.isConnected()) {
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(); //必须关闭蓝牙连接否则意外断开的话打印错误
}
},
直接连接报错Uncaught java.io.IOException: read failed, socket might closed or timeout, read ret: -1;at android.bluetooth.BluetoothSocket.connect at index.html:1
2***@qq.com
你好,看了下5+蓝牙的官方api,请问蓝牙配对方法有吗?买有找到,好像只有蓝牙连接设备
2019-03-04 11:35