2

I found the tutorial of client (android) and server (pc) bluetooth tutorial from here.

But my question is about the UUID.

Is that okay if we define it randomly without the proper format? Because I heard UUID is generally for ID for each devices just like IP address used right?

For example like this, instead of the following code:

UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");

I define my own UUID

UUID.fromString("myDeviceName009");

Is it okay? I mean is it if i tested on both android device using the above code, they could communicate each other?

CodesInChaos
  • 5,697
  • 4
  • 19
  • 26
gumuruh
  • 123
  • 6

2 Answers2

8

No. A UUID has a particular, standardised format.

From the wiki article on the subject:

In its canonical form, a UUID is represented by 32 lowercase hexadecimal digits, displayed in five groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters (32 alphanumeric characters and four hyphens).

Andy Hunt
  • 5,996
  • 1
  • 33
  • 56
  • so, each device should define its own UUID? i see, what about if I set "00001101-0000-1000-8000-00805f9b34fb" for my Device A, and for Device B i just differentiate the last digit? become, "00001101-0000-1000-8000-00805f9b34fc" is it fine? I mean wouldn't it be conflict to the other UUID? @AndyBursh – gumuruh Jul 07 '14 at 07:31
  • 1
    Each device should have a UUID, as I understand it, yes. However, I don't know enough about that platform to say whether you need to set it yourself, or get it from the device. – Andy Hunt Jul 07 '14 at 07:33
  • 5
    Just for the sake of clarity: an UUID (or GUID) is by no means a device ID. It is just an ID that can be used (and in fact, *is* used) for anything that you can think of that needs an ID for some reason. – JensG Jul 07 '14 at 10:27
3

A UUID is a standardised representation of a 128-bit number. As noted by AndyBursh, the representation is 32 hexadecimal digits, split into groups and separated by dashes. Nothing else is a proper UUID, it would just be a string.

The point of a UUID is that it's "universally unique". If I just pick a string that I like the look of, then there's no guarantee that somebody else won't pick the same string.

RFC 4122 defines a number of ways of generating UUIDs so that is is extremely unlikely that two computers will ever generate the same one. This makes it good for device IDs, and almost anything else where you need to attach a unique serial number to something.

Microsoft's GUID is one implementation of a UUID.

Simon B
  • 9,167
  • 4
  • 26
  • 33
  • Except that GUIDs aren't _universally_ unique ;) – Cole Tobin Jul 08 '14 at 05:09
  • @SimonBarker, but that means... I still can use the similar like that string of the UUID towards any device using my own like , wasn't? for example in the Device A: i put : "00001101-0000-1000-8000-00805f9b34fb" and in Device B : i put : "00001101-0000-1000-8000-00805f9b34fc" --> look the difference is the latest character, wouldn't it be okay? – gumuruh Jul 08 '14 at 15:17
  • @gumuruh That second UUID should also be valid. there's a small chance that someone else has already used it for something, but that's very unlikely. – Simon B Jul 09 '14 at 07:59
  • okay then. I'll try for testing it :D @SimonBarker thanks – gumuruh Jul 09 '14 at 08:01