简体   繁体   English

蓝牙连接设备

[英]Bluetooth connected device

I am wondering if there is any way to check if the device we want to connect to is already connected to the phone.我想知道是否有任何方法可以检查我们要连接的设备是否已经连接到手机。 In my case, the device pairs itself to the phone, and connects automatically.在我的例子中,设备将自己与手机配对,并自动连接。

I have not found a way yet to check if the device is already connected before scanning.我还没有找到在扫描之前检查设备是否已经连接的方法。

I expect something like this:我期待这样的事情:

  1. I turn on Bluetooth on my phone.我打开手机上的蓝牙。
  2. I turn on Bluetooth on my device.我在我的设备上打开蓝牙。
  3. The phone automatically connects to device (because they have previously paired and "know" each other).手机会自动连接到设备(因为它们之前已经配对并且彼此“认识”)。
  4. I don't want to run any scanning to find any possible devices.我不想运行任何扫描来查找任何可能的设备。
  5. I want to show in my app that device is connected.我想在我的应用程序中显示该设备已连接。
  6. I want to listen to the status of connection and if the device disco.nets I want to show that as well.我想听听连接状态,如果设备 disco.nets 我也想展示它。

I may be wrong, but every external library like flutter_reactive_ble or flutter_blue_plus has a flow like:我可能是错的,但是像 flutter_reactive_ble 或 flutter_blue_plus 这样的每个外部库都有这样的流程:

  1. Scan for devices扫描设备
  2. Connect to the found device连接到找到的设备
  3. When library know about connected device than it can listen its status.当库知道连接的设备时,它就可以监听它的状态。

In my application I just want to know if a device with a certain mac address is connected to the phone the app is running on.在我的应用程序中,我只想知道具有特定 mac 地址的设备是否已连接到运行该应用程序的手机。

According to this Github issue , you can use FlutterBluePlus.instance.connectedDevices to see a list of all devices connected since FlutterBluePlus was initialized.根据这个 Github 问题,您可以使用FlutterBluePlus.instance.connectedDevices查看自 FlutterBluePlus 初始化以来连接的所有设备的列表。 That would allow you to check the list for a specific device.这将允许您检查特定设备的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM