how to create a unique GUID

21 views
Skip to first unread message

Mark Bolduc

unread,
May 10, 2020, 11:25:34 AM5/10/20
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA Netbeans 11.3
Desktop OS Windows 10 Pro
Simulator Latest
Device ALL

How can I create a unique client identifier (GUID)
Log.getUniqueDeviceId() is deprecated and returns -1;

Thoughts?

Regards

Marisole Aromatherapy

unread,
May 10, 2020, 12:00:55 PM5/10/20
to codenameone...@googlegroups.com
Hi marcus,

have a look at this

public String getRandomHexBlob() {
        Random r = new Random();
        StringBuffer sb = new StringBuffer();
        while (sb.length() < 32) {
            sb.append(Integer.toHexString(r.nextInt()));
        }

        return sb.toString().substring(0, 32).toUpperCase();
    }

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/d05170ce-671f-4481-abe8-aa165b3405fe%40googlegroups.com.

Shai Almog

unread,
May 10, 2020, 10:08:55 PM5/10/20
to CodenameOne Discussions
The original UUID code used a server side to get a truly unique id but it would be different for each install (which might be OK). Technically, this is a much harder problem than one would immediately expect due to privacy laws. So I suggest backtracking and thinking why you need that unique id.

Mark Bolduc

unread,
May 10, 2020, 10:23:38 PM5/10/20
to CodenameOne Discussions
Thanks,

This is used to identify each client to the Server.

Regards.

Shai Almog

unread,
May 11, 2020, 10:06:01 PM5/11/20
to CodenameOne Discussions
In that case you have a server and it should assign a unique ID which you can store in the device preferences. Technically this is exactly what Logs unique ID used to do.
Notice that real world apps such as uber/whatsapp etc. use phone numbers to identify devices and actually physically ask you to type in your phone number. Phone APIs to query the phone number are restricted and even in-accessible usually.

Dave Dyer

unread,
May 12, 2020, 6:11:31 PM5/12/20
to CodenameOne Discussions

My requirements aren't too strict - I remember a value stored with the properties API, and generate it from the
current time of day (millisecond precision). 

Reply all
Reply to author
Forward
0 new messages