Connect to a Bluetooth Serial Device with Xamarin.Android

I have been exploring the Xamarin tools recently and decided to try my hand at connecting some Bluetooth hardware to Android for a project that will be released soon. I have learned quite a bit about Bluetooth on Android and decided to write up a short description on how to connect to a Bluetooth serial device via RFCOMM/SPP.

First, grab an instance of the default BluetoothAdapter on the Android device and determine if it is enabled:

BluetoothAdapter adapter = BluetoothAdapter.DefaultAdapter;
if(adapter == null)
    throw new Exception("No Bluetooth adapter found.");

if(!adapter.IsEnabled)
    throw new Exception("Bluetooth adapter is not enabled.");

Next, get an instance of the BluetoothDevice representing the physical device you’re connecting to. You can get a list of currently paired devices using the adapter’s BondedDevices collection. I use some simple LINQ to find the device I’m looking for:

BluetoothDevice device = (from bd in adapter.BondedDevices …
Read More