android - Android 上的 Nativescript 蓝牙只发现了一些设备并慢慢地进行

标签 android bluetooth nativescript nativescript-plugin

我目前正在开发一个电话应用程序,使用 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/

相关文章:

android - 如何在android中使用光标获取单行?

android - 查找 Android 蓝牙配对设备

javascript - 如何拒绝 NativeScript 上的 promise - Angular 2

ios - NativeScript 平面 ActionBar 重叠 ScrollView

ios - iOS 上的通用 url 方案

java - 先执行服务器调用,然后执行下一行代码

android - 我的应用无法安装在 HVGA 设备上

android - 从 Activity 到 Main Activity 的返回列表?

Android 蓝牙连接安全不安全

java - 如何找到蓝牙设备之间的距离