Using bluetooth handsfree

Topics: Bluetooth - Microsoft
May 28, 2012 at 1:46 PM

 am trying to use 32fleet with Windows Mobile 6.5 to connect to a bluetooth handsfree kit from within my applications. I need to pair the device to my phone, I am using the following code to do this.

BluetoothAddress BTAddress;
BluetoothClient BTClient = new BluetoothClient();
BluetoothEndPoint BTEndPoint;
Guid spguid = BluetoothService.Headset;
BTAddress = BluetoothAddress.Parse(cmbDevices.SelectedValue.ToString());
BTEndPoint = new BluetoothEndPoint(BTAddress, spguid);
BluetoothSecurity.PairRequest(BTAddress, "0000");
Application.DoEvents();

I can see the device has been paired from the Windows Mobiles bluetooth control panel, the icon for the device even shows as a headset. The problem is that for some reason the device has not been automatically detected as a handsfree kit. Here are some screenshots http://imageshack.us/photo/my-images/16/bluetooth1g.jpg/ http://imageshack.us/photo/my-images/51/bluetooth2w.jpg/ I have to manually add the hands free service. http://imageshack.us/photo/my-images/341/bluetooth3.jpg/

I am using the Microsoft Software Stack, any help would be greatly appreciated. Phil

May 29, 2012 at 9:35 AM

Sorry I forgot to mention I enable the service using 

 

BluetoothDeviceInfo deviceInfo = new BluetoothDeviceInfo(BTAddress);               

deviceInfo.SetServiceState(spguid, true);

 

It is very flaky, sometimes the handsfree works and sometimes it doesnt even though a pairing has been made :(

 

Phil

Developer
May 29, 2012 at 8:30 PM

Ahh.  I was just going to write: Try BluetoothDeviceInfo.SetServiceState(BluetoothService.Headset, true) x

Are things "very flaky" even if you set the checkbox manually through the UI?

May 30, 2012 at 8:09 AM
Edited May 30, 2012 at 8:42 AM

Ok, for some reason the headset connects better if I set the radio mode to discoverable. The headset works fine but in the bluetooth settings it still doesnt have the handsfree checkbox set by default. In this pda application the settings are locked down to prevent users for messing around with the settings. 

 

The only problem I seem to have now is if the user attempts to re-pair the device even though it has already been done before (The people using this pda application are not the smartest people in the world). What I have tried is to remove the pairing using...

 unpairResult = BluetoothSecurity.RemoveDevice(BTAddress);               

 Application.DoEvents();

 

This is returning true, but then when I try to remake the pairing true is returned but the headset stays in the searching for device mode.

 pairResult = BluetoothSecurity.PairRequest(BTAddress, txtKeyCode.Text.Trim());

 

Essentially we have a fleet of staff using a PDA, they want to connect their PDA to handsfree kits built into vehicles. Each day a member of staff may use a different vehicle. I think these hands free kits only allow 1 device to be paired at once. So I may have the problem where a user used a certain vehicle 1 day and returns to it a few days later. Someone else may have paired their phone to this vehicle in that time. So my Windows PDA will still have the pairing setup but the vehicle will not.

I was thinking I need to remove the pairing from my phone and starting from scratch again. So I try to remove the device and then do a pair request. Like I said above this does not seem to work correctly. After removing the pairing and then performing a pair request the headset still stays in the searching mode. 

Do you have any ideas about a solution to my problem? :D 

Thank you