Pairing a Bluetooth device with Numeric Comparison

Topics: Bluetooth - Microsoft
Aug 31, 2013 at 5:17 PM
Edited Aug 31, 2013 at 5:18 PM
Hey guys, I am trying to develop a C# application which automatically pairs with selected bluetooth device. I'm able to search and attempt to pair with the device. When I pair with my Iphone, my Iphone shows an 8-pin numeric comparison as well as the application. But when I click confirmed, nothing happen because I have to click YES in my Windows 7 bluetooth notification.

Is there any way I can accept the comparison through the application and my Iphone and not need to accept the comparison on windows again? This is what I have so far,

Here is where I search for the device and pair it.
BluetoothWin32Authentication oBluetoothWin32Authentication = new BluetoothWin32Authentication(handler);
Bclient.Connect(new BluetoothEndPoint(device.DeviceAddress, BluetoothService.RFCommProtocol));

And this is what I have in my eventhandler
        public void handler(Object sender, BluetoothWin32AuthenticationEventArgs e)
        {


                if (e.JustWorksNumericComparison == true)
                {
                    MessageBox.Show("1");
                    e.Confirm = true;
                }
                else if (e.AuthenticationMethod == BluetoothAuthenticationMethod.NumericComparison)
                {
                    MessageBox.Show("2");
                    var result = MessageBox.Show("Pairing : " + e.NumberOrPasskeyAsString, "Pairing",
                                     MessageBoxButtons.YesNo,
                                     MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        e.Confirm = true;
                    }
                }
                else if (e.AuthenticationMethod == BluetoothAuthenticationMethod.Legacy)
                {
                    MessageBox.Show("3");
                    e.Confirm = true;
                }
                else if (e.AuthenticationMethod == BluetoothAuthenticationMethod.PasskeyNotification)
                {
                    MessageBox.Show("4");
                    e.Confirm = true;
                }
                else if (e.AuthenticationMethod == BluetoothAuthenticationMethod.Passkey)
                {
                    MessageBox.Show("5");
                    e.Confirm = true;
                }
                else if (e.AuthenticationMethod == BluetoothAuthenticationMethod.OutOfBand)
                {
                    MessageBox.Show("6");
                    e.Confirm = true;
                }     
        }
Please advice. Thank you.
Developer
Sep 8, 2013 at 6:54 PM
Looks about right. Does it not work? Is the event handler called?

(Any chance oBluetoothWin32Authentication is getting finalized? If so add e.g. GC.Keepalive etc.)
Sep 27, 2013 at 1:42 PM
alanjmcf wrote:
Looks about right. Does it not work? Is the event handler called?

(Any chance oBluetoothWin32Authentication is getting finalized? If so add e.g. GC.Keepalive etc.)
Hi alan, I've got it working already. However, is there any possible way where I can disable Windows notification while using my application? As in, I do not want Windows 7 to prompt me about a device pairing or file transfer whenever I am connecting using the application.

Thanks for your help.
Oct 11, 2013 at 1:14 PM
Edited Oct 11, 2013 at 1:14 PM
Hi, I am having the same exact problem with Windows 7's pairing notification popping up with Numeric Comparison.
This happens when Windows 7 does not have pairing information and when my 32feet application initially trying to connect to the device,
my 32feet bluetooth application will pair the devices automatically and able to communicate with no problems, BUT

The Windows 7 does not recognize that the device has been paired already and asks to pair the devices again using the OS's adding device dialog. When I click OK on the dialog, it ends in an error.

Is there anyway to notify the OS that the device is paired already and there is no need for adding device notification?
In the application I am setting the e.Confirm = true and e.ResponseNumberOrPasskey = [TheCorrectPasskeyValue]

Has anybody got this working? Thank you in advance.
Developer
Oct 13, 2013 at 11:36 AM
I don't know of a way of suppressing the Windows pairing that pops up for an unpaired device.

@btnoobie are you saying that that dialog pops up for subsequent connects? Or just the first one?
Oct 14, 2013 at 3:02 PM
Edited Oct 14, 2013 at 3:02 PM
@alanjmcf
The dialog pops up for the first connection, and will not pop up for the subsequent connects.
After the first connection, I can find my device in the Bluetooth devices folder from the control panel.
If I delete my device from the control panel the next connection will pop up the "add devices dialog" notification again.
Oct 26, 2013 at 8:13 AM
btnoobie1234 wrote:
@alanjmcf
The dialog pops up for the first connection, and will not pop up for the subsequent connects.
After the first connection, I can find my device in the Bluetooth devices folder from the control panel.
If I delete my device from the control panel the next connection will pop up the "add devices dialog" notification again.
Try disabling your windows bluetooth discovery option and the sharing options.