[android] 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?

This question is related to android bluetooth uuid rfcomm

The answer is


To sum up: UUid is used to uniquely identify applications. Each application has a unique UUid

So, use the same UUid for each device


UUID is similar in notion to port numbers in Internet. However, the difference between Bluetooth and the Internet is that, in Bluetooth, port numbers are assigned dynamically by the SDP (service discovery protocol) server during runtime where each UUID is given a port number. Other devices will ask the SDP server, who is registered under a reserved port number, about the available services on the device and it will reply with different services distinguishable from each other by being registered under different UUIDs.


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).


UUID is just a number. It has no meaning except you create on the server side of an Android app. Then the client connects using that same UUID.

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

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

Your Android server program will listen for incoming requests with that UUID like this:

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

BluetoothSocket socket = server.accept();


The UUID stands for Universally Unique Identifier. UUID is an simple 128 bit digit which uniquely distributed across the world.

Bluetooth sends data over air and all nearby device can receive it. Let's suppose, sometimes you have to send some important files via Bluetooth and all near by devices can access it in range. So when you pair with the other devices, they simply share the UUID number and match before sharing the files. When you send any file then your device encrypt that file with appropriate device UUID and share over the network. Now all Bluetooth devices in the range can access the encrypt file but they required right UUID number. So Only right UUID devices have access to encrypt the file and others will reject cause of wrong UUID.

In short, you can use UUID as a secret password for sharing files between any two Bluetooth devices.


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


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to bluetooth

Sniffing/logging your own Android Bluetooth traffic Android sample bluetooth code to send a simple string via bluetooth Understanding ibeacon distancing Connect multiple devices to one device via Bluetooth What is the iBeacon Bluetooth Profile Transfer data between iOS and Android via Bluetooth? IOException: read failed, socket might closed - Bluetooth on Android 4.3 Android + Pair devices via bluetooth programmatically Android: How do bluetooth UUIDs work? How to receive serial data using android bluetooth

Examples related to uuid

A TypeScript GUID class? How to get a unique device ID in Swift? Which UUID version to use? Is there a method to generate a UUID with go language Android: How do bluetooth UUIDs work? UUID max character length Generating a UUID in Postgres for Insert statement? How can I generate UUID in C# How to test valid UUID/GUID? How can I get the UUID of my Android phone in an application?

Examples related to rfcomm

Android: How do bluetooth UUIDs work?