Reputation: 21
I was using UUId and calling it whenever accessing particular file in the folder named with the value of deviceId. It is changing every time the function is called. What I was thinking it is regenerating the UUId with some random number functionality.
The code snippet is below:
String getDeviceInformation() {
this.deviceId = UUID.randomUUID().toString(); // UUId
return this.deviceId;
}
Does anyone know what is wrong here, or how can I optimize it?
Upvotes: 2
Views: 3621
Reputation: 9574
Identifying a unique identifier for an Android device is challenging. We have solved it like this.
For Android Emulators you may get duplicate's.
Each unique id has its own weaknesses and null possibilities. A hashed string with a combination of them will break your uniqueness requirement for all those combinations. Analyze the weakness of all id's and decide which one you are willing to live with, and hash that one. May be hash it with the timestamp (which you store in your backend db, and no one knows about). That will give you the randomness (and unencryption security issue) for sure.
Upvotes: 0
Reputation: 78995
This method will always return you the same UUID.
Demo:
import java.util.UUID;
public class Main {
public static void main(String[] args) {
System.out.println(UUID.fromString("313701fc-c222-488d-b9c9-432237413155"));
}
}
Output:
313701fc-c222-488d-b9c9-432237413155
You can generate such a string by calling UUID.randomUUID().toString()
and hardcode the same into your code to sustain reinstallation.
Upvotes: 2