Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How do bluetooth UUIDs work?

I don't understand what a bluetooth UUID denotes. Do UUIDs denote protocols (e.g. RFCOMM)? If so, why do the createRfcommSocketToServiceRecord() methods require UUIDs, when they specify rfcomm right in their names? Why does the BluetoothChat sample code have a seemingly arbitrary, hardcoded UUID?

My question arises because, as per this question, I'm getting a null pointer exception when devices running 4.0.4 try to connect (to an external, non-android device) using reflection. However, the solution to that question doesn't work for me. UUID muuid = device.getUuids()[0].getUuid(); raises an exception.

Edit: I've solved that problem by hardcoding the UUID for Serial port service as per this answer (using UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");).

I'm further puzzled by why I need to supply a UUID to create an unsecured rfcomm socket using createInsecureRfcommSocketToServiceRecord(), but not using the reflection method.

Can anyone straighten me out?

like image 528
ForeverWintr Avatar asked Dec 20 '12 02:12

ForeverWintr


People also ask

What is a UUID in Android?

UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are multiple, variant layouts of UUIDs, but this class is based upon variant 2 of RFC 4122, the Leach-Salz variant.

What is Bluetooth scanning Android?

Device discovery is a scanning procedure that searches the local area for Bluetooth-enabled devices and requests some information about each one.

What is UUID used for in Ble?

A Universally Unique Identifier (UUID) is a globally unique 128-bit (16-byte) number that is used to identify profiles, services, and data types in a Generic Attribute (GATT) profile. For efficiency, the Bluetooth® Low Energy (BLE) specification adds support for shortened 16-bit UUIDs.

What is a UUID on a cell phone?

A UUID (Universal Unique Identifier) is a 128-bit value used to uniquely identify an object or entity on the internet.


2 Answers

The UUID is used for uniquely identifying information. It identifies a particular service provided by a Bluetooth device. The standard defines a basic BASE_UUID: 00000000-0000-1000-8000-00805F9B34FB.

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

So, an Android phone can connect to a device and then use the Service Discovery Protocol (SDP) to find out what services it provides (UUID).

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

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

like image 171
GVillani82 Avatar answered Sep 20 '22 15:09

GVillani82


It usually represents some common service (protocol) that bluetooth device supports.

When creating your own rfcomm server (with listenUsingRfcommWithServiceRecord), you should specify your own UUID so that the clients connecting to it could identify it; it is one of the reasons why createRfcommSocketToServiceRecord requires an UUID parameter.

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

See here

like image 32
nullpotent Avatar answered Sep 21 '22 15:09

nullpotent