0

I'm trying to connect a remote device from Android via Bluetooth in .NET / C# with the following code:

const string GUID_RFCOMM_SERIALPORT = "00001101-0000-1000-8000-00805f9b34fb";
BluetoothDevice.CreateRfcommSocketToServiceRecord(UUID.FromString(GUID_RFCOMM_SERIALPORT));

... but I miss an option, to select a Service name.

If I listen for incoming connections, I have to offer the service name:

BluetoothAdapter.ListenUsingRfcommWithServiceRecord("MyServiceName", UUID.FromString(GUID_RFCOMM_SERIALPORT));

How can I choose a special service name while connecting a remote Bluetooth device?

Mike Irving
  • 1,480
  • 1
  • 12
  • 20
  • It is just a name to identify the service record you create for the ***BluetoothSocketServer*** created by the private ***BluetoothAdapter.createNewRfcommSocketAndRecord()*** method. It can be any name but you can use your app package name. https://android.googlesource.com/platform/frameworks/base/+/kitkat-release/core/java/android/bluetooth/BluetoothAdapter.java#1049 – ecle Oct 18 '22 at 04:32
  • You will only need the UUID, not the service name, to connect to the Bluetooth socket server with a Bluetooth socket https://stackoverflow.com/questions/30813854/how-do-bluetooth-sdp-and-uuids-work-specifically-for-android – ecle Oct 18 '22 at 04:44
  • @ede: It's possible, that two different apps are listening on the same UUID with different service names. To connect to the right one of both, I have to use the service name. So you are wrong: It's not just a name, it's a selector. –  Oct 18 '22 at 05:40
  • I still wonder about the real use of the service name since for a BT client to establish a connection to a BT socket server, it only needs to know the UUID rather than the service name. Once connected, can we know the server socket's service name remotely from the client side? – ecle Oct 19 '22 at 09:40
  • I'm referring to this answer for the multiple BT client connections question to see how BT clients can use the service name from a BT socket server, but I couldn't find a real use case for it. It is only used once to configure the BT socket server. https://stackoverflow.com/questions/13497103/multi-connection-via-bluetooth-in-android – ecle Oct 19 '22 at 10:13

0 Answers0