74

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,924
  • 10
  • 36
  • 47

4 Answers4

90

Yes you should use UUID like the following code:

String  uniqueID = UUID.randomUUID().toString(); 
Brian Mains
  • 50,194
  • 35
  • 142
  • 253
Behnam Bagheri
  • 901
  • 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
82

You can use the java.util.UUID class.

CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367
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
  • 3,792
  • 3
  • 20
  • 30
Vinod Pattanshetti
  • 2,295
  • 3
  • 21
  • 34
2

You will get UUID in Android,

UUID uuid = UUID.randomUUID();
String uuidInString = uuid.toString();
Parth Pandya
  • 51
  • 1
  • 3