Android: How do UUIDs for Bluetooth work?

I do not understand what UUID Bluetooth means. Do UUIDs mean protocols (e.g. RFCOMM )? If so, why do the createRfcommSocketToServiceRecord() methods require a UUID when they specify rfcomm directly in their names? Why does the BluetoothChat code code have a seemingly arbitrary, hard-coded UUID?

My question arises because, on this issue , I get a null pointer exception when devices running 4.0.4 try to connect (to an external, -android device) using reflection. However, resolving this issue does not work for me. UUID muuid = device.getUuids()[0].getUuid(); raises an exception.

Change I solved this problem by hard-coding the UUID for the Serial Port service according to this answer (using UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); ).

I am also puzzled by why I need to provide a UUID for creating an insecure rfcomm socket using createInsecureRfcommSocketToServiceRecord(), , but not using the reflection method.

Can anyone straighten me?

+71
android uuid bluetooth rfcomm
Dec 20 '12 at 2:21
source share
6 answers

Usually this is some kind of common service (protocol) that a Bluetooth device supports.

When creating your own rfcomm server (using listenUsingRfcommWithServiceRecord ), you must specify your own UUID so that clients connecting to it can identify it; this is one of the reasons why createRfcommSocketToServiceRecord requires a UUID parameter.

Otherwise, some shared services have the same UUID, just find the one you need and use it.

Look here

+20
Dec 20
source share
โ€” -

UUID is used to uniquely identify information. It identifies the specific service provided by the Bluetooth device. The standard defines the base BASE_UUID: 00000000-0000-1000-8000-00805F9B34FB .

Devices, such as health sensors, can provide a service by replacing the first eight digits with a predefined code. For example, a device that offers an RFCOMM connection uses a short code: 0x0003

In this way, the Android phone can connect to the device and then use the service discovery protocol (SDP) to find out what services it provides (UUID).

In many cases, you do not need to use these fixed UUIDs. In case you are creating a chat application, for example, one Android phone interacts with another Android phone that uses the same application and therefore the same UUID.

Thus, you can set an arbitrary UUID for your application using, for example, one of the many random UUID generators on the Internet ( for example ).

+25
Feb 13 '14 at 16:38
source share

The UUID is similar to the port numbers on the Internet. However, the difference between Bluetooth and the Internet is that in Bluetooth, port numbers are dynamically assigned by the SDP server (service discovery protocol) at run time, when a port number is assigned to each UUID. Other devices will request from the SDP server, which is registered under the reserved port number, about the available services on the device, and it will respond with different services that differ from each other, being registered in different UUIDs.

+5
Feb 14 '14 at 3:49
source share

UUID is just a number. It does not make any difference, except that you create server-side applications for Android. The client then connects using the same UUID.

For example, on the server side, you can first run uuid = UUID.randomUUID () to generate a random number such as fb36491d-7c21-40ef-9f67-a63237b5bbea. Then save this and then the hard code that will be in your listening program as follows:

  UUID uuid = UUID.fromString("fb36491d-7c21-40ef-9f67-a63237b5bbea"); 

Your Android server program will listen for incoming requests with this UUID as follows:

  BluetoothServerSocket server = mBluetoothAdapter.listenUsingRfcommWithServiceRecord("anyName", uuid); 

BluetoothSocket socket = server.accept ();

+4
Jul 09 '15 at 17:28
source share

To summarize: UUid used to uniquely identify applications. Each application has a unique UUid

So use the same UUid for each device

+1
Dec 21 '12 at 16:15
source share

In Bluetooth, all objects are identified by UUID. These include services, features and more. Bluetooth maintains a database of assigned numbers for standard objects and assigns subbands to providers (who paid enough for a reservation). You can view this list here:

https://www.bluetooth.com/specifications/assigned-numbers/

If you are introducing a standard service (for example, a serial port, a keyboard, a headset, etc.), you should use this UUID service standard - this will allow you to interact with devices that you have not developed.

If you are implementing a custom service, you should generate unique UUIDs to make sure that incompatible third-party devices are not trying to use your service, thinking it is something else. The easiest way is to generate random ones and then hard-code the result in your application (and, of course, use the same UUIDs on devices that will connect to your service).

0
Jul 03 '19 at 21:02
source share



All Articles