2017-08-28 46 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的離子原生文檔。