我目前正在开发一个电话应用程序,使用 nativescript 和蓝牙(我对这两者都很陌生)并且我在发现附近的设备时遇到了问题。在另一个手机应用程序上,许多设备的发现速度非常快,但是,在我的应用程序上,只发现了其他应用程序发现的设备的一个子集,而且它们发现的速度也较慢。所以我的主要问题是什么可能导致我的应用程序只发现我周围的一些设备而不是其他设备?另外,其次为什么发现它们很慢?或者有什么简单的方法可以诊断问题?
这也是我的代码...
import { Component, OnInit } from "@angular/core";
import { ListViewEventData, RadListView } from "nativescript-ui-listview";
import { Device } from "../shared/device.model";
var bluetooth = require('nativescript-bluetooth');
//var bluetooth = require("nativescript-bluetooth");
@Component({
selector: "Home",
moduleId: module.id,
templateUrl: "./home.component.html",
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
deviceList: Array<Device> = [];
isLoading = false;
listLoaded = true;
constructor() {
}
onTapCell(name): void{
alert(name);
return;
}
ngOnInit(): void{
console.log(bluetooth.isBluetoothEnabled().then(
function(enabled){
console.log("enabled " + enabled);
}
));
var t = this.deviceList;
setTimeout(
function(){
bluetooth.startScanning({
serviceUUIDs: [],
seconds : 120,
onDiscovered: function(peripheral){
console.log(peripheral.UUID);
console.log(peripheral.RSSI);
peripheral.RSSI += 128;
t.push(peripheral);
},
onScanFailed: function(){
}
});
},
125*1000
)
}
}
我的系统:Android 8,motoZ2
谢谢, 以赛亚
最佳答案
@Katherine 是也不是,事实证明它使用低功耗蓝牙(蓝牙 LE),它不会向后兼容使用更高功率蓝牙的旧设备。另外,如果我没记错的话(不要引用我的话)图书馆不处理它从设备接收到的初始信号我认为创建者将其作为 git repo 中的 TODO,这可以解释为什么它也很慢。这是存储库 github.com/eddyverbruggen/nativescript-bluetooth 的链接。注意: native android 库应该具有向后兼容的蓝牙。
关于android - Android 上的 Nativescript 蓝牙只发现了一些设备并慢慢地进行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51976639/