Android 将蓝牙设备与React本机应用程序连接
我正在使用本机蓝牙串行。每当我尝试通过react本机应用程序连接蓝牙设备时,都会出现此错误: 错误:读取失败,套接字可能已关闭或超时,读取重试:-1 无法连接到设备 以下是我想做的:Android 将蓝牙设备与React本机应用程序连接,android,react-native,bluetooth,bluetooth-socket,Android,React Native,Bluetooth,Bluetooth Socket,我正在使用本机蓝牙串行。每当我尝试通过react本机应用程序连接蓝牙设备时,都会出现此错误: 错误:读取失败,套接字可能已关闭或超时,读取重试:-1 无法连接到设备 以下是我想做的: connectToDevice () { if (this.state.discovering) { return false } else { this.setState({ discovering: true }) console.log("searchin
connectToDevice () {
if (this.state.discovering) {
return false
} else {
this.setState({ discovering: true })
console.log("searching");
BluetoothSerial.list()
.then((Devices) => {
this.setState({ Devices, discovering: false })
for(var i = 0; 1; i++)
{
if(Devices[i]["name"] == "JBL Flip 3 SE")
{
console.log(Devices[i]["id"]);
BluetoothSerial.connect(Devices[i]["id"]).then((res) => {
console.log(res);
}).catch(err => {
console.log(err);
})
break;
}
}
// console.log(unpairedDevices);
})
.catch((err) => console.log(err.message))
}
}
即使在克隆示例存储库时也会发生同样的情况
知道为什么会发生这种情况吗?我鼓励您在React Native中使用蓝牙,如果您需要现场示例,您可以查看我们的项目,该项目使用此库向Arduino发送颜色并处理LED灯bluetooth classic是否也适用于此库?