I need a unique media id for each media which I will upload on a server in my app, because of some reason I need to create it from the Android side. Can anyone suggest any best way to achieve this?
Asked
Active
Viewed 519 times
-1
-
1better way than which way? – Rohit5k2 Feb 22 '19 at 06:42
-
Possible duplicate of [How can I get the UUID of my Android phone in an application?](https://stackoverflow.com/questions/5088474/how-can-i-get-the-uuid-of-my-android-phone-in-an-application) – Rumit Patel Feb 22 '19 at 06:44
-
This could help https://developer.android.com/training/articles/user-data-ids – Rohit5k2 Feb 22 '19 at 06:45
-
@Rohit5k2 sorry for a wrong word, I want to ask the best way, now I edited my question. – Sazid Ali Feb 22 '19 at 10:05
3 Answers
0
You can generate unique id using below code:
UUID.randomUUID().toString()
it will return a unique string.

subrahmanyam boyapati
- 2,836
- 1
- 18
- 28
0
finally, I find the solution, I am using userId+System.currentTimeMillis() and create a unique code, it is unique for each media and also for each user.

Sazid Ali
- 21
- 7
-1
for unique Id use current Time in miliseconds
System.currentTimeMillis();

Akash Suresh Dandwate
- 167
- 1
- 8
-
-
Easy doesn't mean correct. There is no guarantee of being milliseconds to be unique. What if another user takes the action at the exact same moment? – Rohit5k2 Feb 22 '19 at 06:47
-
its in milliseconds so this will rarely happen and another one solution is by getting device id but what if he want to create multiple unique id then?? – Akash Suresh Dandwate Feb 22 '19 at 06:49
-
Seems you could use some read. https://developer.android.com/training/articles/user-data-ids – Rohit5k2 Feb 22 '19 at 06:50
-
if 2 persons are upload media in-app at the same time it will create the same media id. – Sazid Ali Feb 22 '19 at 10:02
-
I have another one solution. That is generate md5 code of currentTimeInMiliSeconds and your device id that will be always diffrent from others – Akash Suresh Dandwate Feb 22 '19 at 10:27
-
You are funny. If a unit of time changes very fast that doesn't mean only one baby was born. :D – Rohit5k2 Mar 01 '19 at 09:08
-
-
Just tell me how will you generate id at local that will remain unique at serverside – Akash Suresh Dandwate Mar 01 '19 at 09:14