I've a hardware device which tries to connect to the next nearby mobile device. Once it found a device it looks for a specific service and starts sending data. Unfortunately I don't know exactly how the client device is working. I know it searches for a service name and starts the pairing process. When the right pairing code is entered it starts sending data via SPP. The only feedback I have are some error codes shown on a display.
My solution was to create a service record with a specific name and pass this to a BluetoothListener as shown below.
ServiceRecordBuilder bldr = new ServiceRecordBuilder();
bldr.ServiceName = "MyServiceName";
bl = new BluetoothListener(service, bldr.ServiceRecord);
BluetoothClient bc = bl.AcceptBluetoothClient();
The hardware device starts a pairing process and according to the error code I know it found my service. After I've entered the pairing code I'm waiting for the incoming connection to accept. But the problem is that the method AcceptBluetoothClient() never returns.
Did I miss something in my BluetoothListener configuration? Or should I use virtual COM ports instead?
I've a Java demo which works properly with the hardware device:
String url = "btspp://localhost:00112233445566778899AABBCCDDEEFF;name=MyServiceName";
notifier = (StreamConnectionNotifier)Connector.open(url);
// block the current thread until a client responds
con = notifier.acceptAndOpen();
The method acceptAndOpen() returns after I've entered the pairing code and the device connects to my mobile device.