Warm tip: This article is reproduced from serverfault.com, please click

Xamarin Forms with Bluetooth Classic

发布于 2020-11-29 21:08:39

I'm trying to establish a Bluetooth Classic (SPP) connection (i.e. NOT BLE) to a Bluetooth probe within a Xamarin Forms application (for Android and iOS). I have started using this plugin: 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 plugin (which seems very popular). However it appears this plugin only works with BLE devices and can't find Bluetooth Classic devices. Any guidance would be much appreciated :)

Questioner
itcoder
Viewed
0
itcoder 2020-12-08 04:14:19

What I ended up doing was creating an interface within the shared C# project. The Android project of the Xamarin Forms application then implements this functionality for discovering Bluetooth devices using the native BluetoothAdapter class. I can then pass these devices and their addresses back to the shared project using the MessagingCenter. I haven't fully investigated discovering devices in iOS, but at this stage I just use the BluetoothClassic plugin's method for adapter.BondedDevices. Hopefully this is possible on iOS as well, but at this stage it is just a limit of the platform I guess.