Bluetooth Manager for Windows 10

This is a simple little manager that makes it really easy to use Bluetooth with Windows 10. It hides all the nasty device discovery and connection stuff behind a well behaved interface. It makes it really easy to set up a connection to a remote device and bind to events that you can use to drive your user interface.

You can find it on nuget with the boring name of BluetoothManager. You can find it on GitHub here.

I use it to connect to my tiny Bluetooth printer:

private void setupBluetooth()
{
    if (manager != null)
        return;

    manager = new BluetoothManager();

    manager.StatusChangedNotification += 
        new BluetoothManager.StatusChangedDelegate(statusChanged);

    manager.Initialise("PRINTER");
}

This makes a new BluetoothManager instance and binds a method to the StatusChanged event that it fires. 

private void statusChanged(BluetoothManager.ManagerStatus status)
{
    StatusTextBlock.Text = status.ToString();
}

When the status of the Bluetooth connection changes I just display the enum value in a TextBlock.

private async Task sendMessage(string message)
{
    if(manager.Status == BluetoothManager.ManagerStatus.GotConnection)
    {
        return await manager.SendStringAsync(message);
    }
    return false;
}

This is the code that sends a message as a string of text. You can also bind a hander to an event that will fire when you get an incoming message.