Get paired status of a Bluetooth device?

Topics: Bluetooth - Microsoft
Jan 18, 2012 at 8:41 PM
Edited Jan 18, 2012 at 8:42 PM

I am writing a Windows Forms application in C# to connect a Windows 7 computer with an Android device over Bluetooth.

I am able to have the user select a device with which to start a connection, but first I would like to be able to ensure the Android device is paired with the computer.

Making use of InTheHand.Windows.Forms.SelectBluetoothDeviceDialog, I have the user select a device from a list of visible devices:

 

SelectBluetoothDeviceDialog sbtdd = new SelectBluetoothDeviceDialog();

sbtdd.ShowAuthenticated = true;
sbtdd.ShowRemembered = true;
sbtdd.ShowUnknown = true;

 

Now, I get the device that has been selected by the user:

 

 if (sbtdd.ShowDialog() == DialogResult.OK)
{
      _addr = sbtdd.SelectedDevice.DeviceAddress;
      _deviceName = sbtdd.SelectedDevice.DeviceName;
}

 

I would like to be able to get the paired status of the device. I know I can start a pairing request using InTheHand.Net.Bluetooth.BluetoothSecurity.PairRequest like this:

 

BluetoothSecurity.PairRequest(_addr, _PIN);

 

This PairRequest method will send a pairing request to the device with Bluetooth address _addr if the device is not already paired, but won't do anything if the device is already paired. I want to be able to tell the user the PIN, but only if there is going to be a pair request. My problem is that I don't know whether or not the device is paired until I run the PairRequest, but I need to know that info strictly before the request, so that I can optionally alert the user of the request PIN. 

I know I can get some information about the selected device (Authenticated, Connected, Remembered), but is there any way to get the paired status of a device? Maybe I'm just thinking about this wrong...

Thank you in advance for any direction,

Matt

Coordinator
Jan 19, 2012 at 2:57 PM

The SelectedDevice is a BluetoothDeviceInfo and the Authenticated property will tell you if the device was paired with the PC.

Peter

Jan 19, 2012 at 6:34 PM

Hi, Peter. Thank you for your response.

The Authenticated property tells if the device was paired with the PC, but is there any property that will tell if the device is paired? I have a device that was remembered and authenticated but not paired when my program ran, and the Authenticated property was true. Is there anything like an IsPaired property or some way I can make use of Authenticated to figure out the paired status for authenticated but un-paired devices?

I hope that's clear. Thanks again,

Matt

Developer
Jan 20, 2012 at 8:31 PM
Edited Jan 22, 2012 at 9:36 PM

The Authenticate is the 'is-paired' flag, but of course it reports what the local device knows (i.e. whether it has a Link Key for the remote device).  It is NOT possible for it to tell if the remote device has deleted its pairing (i.e. deleted or discarded its copy of the Link Key).  It would have to connect to check that.

Edit: Added missed "NOT".