【发布时间】:2019-08-20 14:35:11
【问题描述】:
谁能指导我如何监控蓝牙设备的连接状态? 当设备断开连接时,我需要通知。请指导。低功耗蓝牙插件是否适用于普通蓝牙?
【问题讨论】:
标签: xamarin.forms
谁能指导我如何监控蓝牙设备的连接状态? 当设备断开连接时,我需要通知。请指导。低功耗蓝牙插件是否适用于普通蓝牙?
【问题讨论】:
标签: xamarin.forms
是的,Shiny 是最常用的插件之一,它是用于后台和设备硬件服务的 Xamarin 框架。
首先你应该阅读这个插件的README.md 文件。它们提供了两个接口,IBluetoothLE 用于帮助您访问蓝牙状态和相关的东西,IAdapter 用于处理设备并与之通信。
以下信息应该有助于您理解插件。
[IBluetoothLE].StateChanged => To know the Bluetooth status, like its off/on
[IAdapter].DeviceDiscovered => This will trigger when any device is discovered
[IAdapter].ConnectToDeviceAsync => For connecting with a device
[IAdapter].GetServicesAsync => To read the Bluetooth device service (The service is
providing the characteristic to read and write the query between connected device)
[service].GetCharacteristicsAsync => To get the characteristics from the selected
service
[characteristic].ReadAsync => Read the data from the device
[characteristic].WriteAsync => Write the data to the device
[characteristic].ValueUpdated => This will trigger when the data through from the
device
[characteristic].StartUpdatesAsync => Start to get the notifying the value updates
Shiny 中几乎每个功能点都有样本。 https://github.com/shinyorg/shinysamples
【讨论】:
您可以使用Shiny。 您将能够获取连接的设备并获取状态更改:
https://shinydocs.azurewebsites.net/docs/ble/central/centralmanager
【讨论】: