Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create UUID from string in android

In my app, I scan low energy Bluetooth for specific service uuid 2415. To convert the string 2415 into uuid I am using UUID serviceUUID = UUID.fromString("2415"); but at this line exception arises IllegalArgumentException: Invalid UUID 2415.

Please help me in this respect I would b very thankful to in this regard. Thanks in advance.

like image 839
user3056760 Avatar asked Dec 02 '13 09:12

user3056760


People also ask

Can you generate UUID from string?

The fromString(String name) method is used to create a UUID from the string standard representation as described in the toString() method.

How do you make a string UUID?

The fromString() method of UUID class in Java is used for the creation of UUID from the standard string representation of the same. Parameters: The method takes one parameter UUID_name which is the string representation of the UUID. Return Value: The method returns the actual UUID created from the specified string.

What is a UUID in Android?

A class that represents an immutable universally unique identifier (UUID). A UUID represents a 128-bit value. There exist different variants of these global identifiers.

How to create a UUID from string in Java?

The fromString () method of UUID class in Java is used for the creation of UUID from the standard string representation of the same. Parameters: The method takes one parameter UUID_name which is the string representation of the UUID. Return Value: The method returns the actual UUID created from the specified string.

How to get the UUID of the device?

* The UUID is generated by using ANDROID_ID as the base key if appropriate, * falling back on TelephonyManager.getDeviceID () if ANDROID_ID is known to * be incorrect, and finally falling back on a random UUID that's persisted * to SharedPreferences if getDeviceID () does not return a usable value.

What is the difference between UUID and Android_ID?

UUID * Returns a unique UUID for the current android device. As with all UUIDs, * devices. Much more so than ANDROID_ID is. * to SharedPreferences if getDeviceID () does not return a usable value. * In some rare circumstances, this ID may change.

Can I use short code UUIDs for Bluetooth devices?

The confusion that may lead many people here is that you can use short code UUIDs to reference bluetooth services and characteristics on other platforms - for instance on iOS with CBUUID . On Android however, you must provide a full, 128-bit length UUID as specified in RFC4122.


2 Answers

Using the class UUID

An example like this:

 UUID.randomUUID().toString() 
like image 82
Alécio Carvalho Avatar answered Oct 08 '22 02:10

Alécio Carvalho


The accepted answer was provided in a comment by @Michael:

Have you tried combining your short UUID with the Bluetooth base UUID? I.e. "00002415-0000-1000-8000-00805F9B34FB"? (assuming that you meant 2415 hexadecimal)?

I'm converting that comment to an answer because I missed it first time I read through this thread.

like image 25
Richard Le Mesurier Avatar answered Oct 08 '22 02:10

Richard Le Mesurier