Bluetooth Device Development using C#

As they say Necessity is mother of invention, I recently got a Jabra BT3030 Bluetooth headset. I paired it to my Windows Mobile phone. When I wanted to turn on the Bluetooth, I had to go to wireless manager and turn it on. I am a little bit lazy and had an idea why not map a button on the phone to toggle the bluetooh radio. But, this is not possible by default, so started working on a program to map to the button.

Fortunately it is very simple to interact with Bluetooth radio and devices on the phone using Windows Embedded Source Tools for Bluetooth Technology. This download contains bunch of C# files which you can directly use in your code. You will get classes such as BluetoothDevice and BluetoothRadio which allow you to control the device and paired devices.

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Text;
    4: using Microsoft.WindowsMobile.SharedSource.Bluetooth;
    5:  
    6: namespace ToggleBluetooth
    7: {
    8:     class Program
    9:     {
   10:         static void Main(string[] args)
   11:         {
   12:             BluetoothRadio brad = new BluetoothRadio();
   13:             if (brad.BluetoothRadioMode == BluetoothRadioMode.Off)
   14:                 brad.BluetoothRadioMode = BluetoothRadioMode.On;
   15:             else
   16:                 brad.BluetoothRadioMode = BluetoothRadioMode.Off;
   17:         }
   18:     }
   19: }

After that, I added a setup project and made sure that a shortcut for the application is under Programs folder, so that I can map it using the Buttons applet of Settings panel. After the install on the device, you should be able to see the program in the "Assign a program" list.

As usual, here are some links and blog post.

Windows Embedded Source Tools for Bluetooth Technology - https://msdn.microsoft.com/en-us/embedded/aa714533.aspx

Channel 9 Wiki (has a good Q&A) - https://channel9.msdn.com/wiki/bluetoothdevelopment/

MSDN Code Samples page - https://msdn.microsoft.com/en-us/library/bb158662.aspx

Thanks

Anil RV