2017-08-28 45 views
1

广告数据对于iPhone而言是可读格式,但对于android而言,它是十进制格式。如何阅读和解释Android的广告数据包。如何从BLE读取广告数据Ionic

this.scanner = this.ble.scan(["00EDSE-0000-00AE-9VVQ-9125475145125"], 1).subscribe((response) => { 
       console.log("success scan.." + JSON.stringify(response)); 
       this.ble.connect(response.id).subscribe((response) => { 
       this.toast.show("Successfully paired", '2000', 'bottom').subscribe((toast) => { 
        console.log(toast); 
        this.spinnerDialog.hide(); 
       }); 

回答

0

Android广告数据以ArrayBuffer的形式收到。您需要将其转换为人类可读的字符串中使用JavaScript的String.fromCharCodemethod

let stringResult = String.fromCharCode.apply(null, new Uint8Array(buffer)); 

buffer是你的advertising财产response对象。您可以找到BLE here的离子原生文档。