75

we are developing the application using the .Net webservice(soap protocal) for that i need Pass GUID from android class.

in .Net we have statement like below Guid myGuid1 = new Guid();

i need the similar functionality in Android , is there any way to make this kind of functionality in android code?

Regards, Jeyavel N

Jeyavel
  • 2,974
  • 10
  • 38
  • 48

4 Answers4

95

Yes you should use UUID like the following code:

String  uniqueID = UUID.randomUUID().toString(); 
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
Behnam Bagheri
  • 951
  • 6
  • 2
  • Note this gives you a type 4 UUID, which is just a random value. The `UUID` class can't generate type 1 UUIDs (time based). – jcayzac Apr 26 '19 at 04:37
  • Sorry, but idk where to add the uniqueID that is generated. Is there a function like "setGUID(parameter)"? – Nacho Jul 08 '21 at 18:20
83

You can use the java.util.UUID class.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
12

We can use

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

An Instance ID or a GUID is scoped to the app that creates it, which prevents it from being used to track users across apps.For more information and significance please refer this link here

rcde0
  • 4,192
  • 3
  • 21
  • 31
Vinod Pattanshetti
  • 2,465
  • 3
  • 22
  • 36
2

You will get UUID in Android,

UUID uuid = UUID.randomUUID();
String uuidInString = uuid.toString();
Parth Pandya
  • 63
  • 1
  • 5