Android 无法从蓝牙串行端口读取蓝牙数据

Android 无法从蓝牙串行端口读取蓝牙数据,android,cordova,typescript,ionic-framework,bluetooth,Android,Cordova,Typescript,Ionic Framework,Bluetooth,我编写了以下代码以在应用程序中的警报消息中显示收到的蓝牙数据 open(item: any){ alert("Selected "); this.bluetoothSerial.connectInsecure("XX:XX:X4:X6:1X:2X").subscribe((data) =>{ alert(JSON.stringify(data)); this.bluetoothSerial.subscribeRawData().subscribe((data) => { al

我编写了以下代码以在应用程序中的警报消息中显示收到的蓝牙数据

open(item: any){
alert("Selected ");
this.bluetoothSerial.connectInsecure("XX:XX:X4:X6:1X:2X").subscribe((data) =>{
  alert(JSON.stringify(data));
  this.bluetoothSerial.subscribeRawData().subscribe((data) => { alert("Subscription : " + JSON.stringify(data))});
});
setTimeout(() => {
  this.bluetoothSerial.read().then((data) => { alert("read data : " +JSON.stringify(data))});
}, 2000);
}

发送蓝牙信号时,“订阅”警报框和“读取数据”警报框均显示空字符串,且不显示实际发送的数据。如何配置离子蓝牙串行包以显示接收到的蓝牙数据

请尝试删除超时并在subscribeRawData()中调用read(),如下所示:

open(item: any){
alert("Selected ");
this.bluetoothSerial.connectInsecure("XX:XX:X4:X6:1X:2X").subscribe((data) {
    alert(JSON.stringify(data));
    this.bluetoothSerial.subscribeRawData().subscribe((data) => { 
            alert("Subscription : " + JSON.stringify(data));
            this.bluetoothSerial.read().then((data) => { alert("read data : " +JSON.stringify(data))});
        });
    });
}

请尝试删除超时并在subscribeRawData()内调用read(),如下所示:

open(item: any){
alert("Selected ");
this.bluetoothSerial.connectInsecure("XX:XX:X4:X6:1X:2X").subscribe((data) {
    alert(JSON.stringify(data));
    this.bluetoothSerial.subscribeRawData().subscribe((data) => { 
            alert("Subscription : " + JSON.stringify(data));
            this.bluetoothSerial.read().then((data) => { alert("read data : " +JSON.stringify(data))});
        });
    });
}