KJEjava48
KJEjava48

Reputation: 2055

How to generate UUID in android using device id and current timestamp

In my android application i want to create uuid for identifier primary key in each table entry so that it should be unique among 1000's of users in my server.So whenever a new record is inserted a random uuid/guid should be generated with the device id,current timestamp,etc. to the identifier field instead of a auto-generated integer value.How can i do that in android? Please help me.

Upvotes: 1

Views: 4302

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199805

To build a unique UUID, you should use the UUID class:

String uuid = UUID.randomUUID().toString();

It is already based on the current timestamp and does not rely on any personally identifiably information such as device id (most of which require a runtime permission).

Upvotes: 1

Related Questions