bluetooth listener cannot detect bluetooth connection

Topics: Bluetooth - Other
Dec 7, 2012 at 11:04 AM
Edited Dec 7, 2012 at 11:05 AM

Hello,

I am trying to use bluetooth to detect if a phone is connected to my computer. after reading the documentation, i think i must followexample for bluetooth listener in this link:  http://32feet.codeplex.com/wikipage?title=Bluetooth%20Server-side&referringTitle=Documentation

my program is in c#and i am trying to listen on the specified service identifier(in my case, bluetoothsevice.handsfree).

here are my program:

 

bl = new BluetoothListener(BluetoothService.Handsfree);
bl.ServiceName = BluetoothService.GetName(BluetoothService.RFCommProtocol);// "32feet.NET Chat2";
bl.Start();
try{
      MessageBox.Show("start");
      bc = bl.AcceptBluetoothClient();
      MessageBox.Show("test");
}

 

when i run this part, application stuck in line

bc = bl.AcceptBluetoothClient();

has anyone meet this problem? is the problem from my program or also from bluetooth setting?

Developer
Dec 8, 2012 at 4:26 PM

That won't work. BluetoothListener is used to accept a connection to a particular application/service on the device. Unless the client device has an application that connects to that particular service then BtLsnr won't get a connection and thus will never return from a call to Accept.

If you're using desktop Windows the Microsoft stack then use BluetoothDeviceInfo.Connected, e.g.

BluetoothAddr myAddr = .......
var dev = new BluetoothDeviceInfo(myAddr);
var connected = dev.Connected;

As you'll see from http://32feet.codeplex.com/wikipage?title=Feature%20support%20table&referringTitle=Documentation the only other platform that has any support for Connected is BlueSoleil.