Xamarin Forms with Bluetooth Classic
Xamarin Forms with Bluetooth Classic
我正在尝试在 Xamarin Forms 应用程序(针对 Android 和 iOS)中与蓝牙探测器建立蓝牙经典 (SPP) 连接(即 NOT BLE)。我已经开始使用这个插件:https://github.com/rostislav-nikitin/Plugin.BluetoothClassic. Which appears to be working fine for the most part, but there appears to be no way of discovering new devices using this plugin. It only allows for connecting to currently bonded devices, which is strange as it has a startDiscovery
method. I can't work out how to handle when a device is discovered. Additionally, I have tried using https://github.com/xabre/xamarin-bluetooth-le 插件(看起来很流行)。然而,该插件似乎仅适用于 BLE 设备,无法找到蓝牙经典设备。任何指导将不胜感激:)
我最后做的是在共享的 C# 项目中创建一个接口。然后,Xamarin Forms 应用程序的 Android 项目实现了使用本机 BluetoothAdapter class 发现蓝牙设备的功能。然后我可以使用 MessagingCenter
将这些设备及其地址传回共享项目。我还没有完全研究在 iOS 中发现设备,但在这个阶段我只是使用 BluetoothClassic 插件的方法 adapter.BondedDevices
。希望这在 iOS 上也是可能的,但在这个阶段,我猜这只是平台的限制。
我正在尝试在 Xamarin Forms 应用程序(针对 Android 和 iOS)中与蓝牙探测器建立蓝牙经典 (SPP) 连接(即 NOT BLE)。我已经开始使用这个插件:https://github.com/rostislav-nikitin/Plugin.BluetoothClassic. Which appears to be working fine for the most part, but there appears to be no way of discovering new devices using this plugin. It only allows for connecting to currently bonded devices, which is strange as it has a startDiscovery
method. I can't work out how to handle when a device is discovered. Additionally, I have tried using https://github.com/xabre/xamarin-bluetooth-le 插件(看起来很流行)。然而,该插件似乎仅适用于 BLE 设备,无法找到蓝牙经典设备。任何指导将不胜感激:)
我最后做的是在共享的 C# 项目中创建一个接口。然后,Xamarin Forms 应用程序的 Android 项目实现了使用本机 BluetoothAdapter class 发现蓝牙设备的功能。然后我可以使用 MessagingCenter
将这些设备及其地址传回共享项目。我还没有完全研究在 iOS 中发现设备,但在这个阶段我只是使用 BluetoothClassic 插件的方法 adapter.BondedDevices
。希望这在 iOS 上也是可能的,但在这个阶段,我猜这只是平台的限制。