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 :)
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.
Could you provide example code on how did you exactly do this? This would be very handy. Thanks.
Hi @Radek, I can't provide exact example code. But this was possible through the
DependencyService
. The MSDocs have a really good documentation here: docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/…