2

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?

2
  • 1
    It's doing exactly what you ask: creating a random UUID every time. You probably want to be creating it once and storing it somewhere like SharedPreferences. Commented Jun 6, 2020 at 5:57
  • 1
    Yeah, but what about reinstalling the app. Won't it be changed? Commented Jun 6, 2020 at 6:31

2 Answers 2

2

UUID#fromString(String name)

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 

Where to get such a string from?

You can generate such a string by calling UUID.randomUUID().toString() and hardcode the same into your code to sustain reinstallation.

Sign up to request clarification or add additional context in comments.

1 Comment

Ooh, okay, let me try.
0

Identifying a unique identifier for an Android device is challenging. We have solved it like this.

  • check for secureAndroidID if not null use it
  • if secureAndroidID is null, check for uuid, if not null use it
  • if uuid is null, check for IMEI, if not null use it

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.

7 Comments

secureAndroidID can be null? I've been using it for year and never encounter a device where it's null... at least not yet
I will try. Actually I want to create a hashed string from the combination of serial-id, Android-Id, UUId, IMEI etc.
@sebasira, it is known to be null sometimes, and can change upon factory reset. Use at your own risk, and it can be easily changed on a rooted phone.
@SayanShankhari dont go for a hashed combination of unique string, since then your uniqueness will be dependent on weaknesses of all the id's you use. Analyze the weakness of all id's and decide which one you are willing to live with.
Dont forget to accept the correct answer to this question. This will help people in future to refer to the closest answer. Also dont forget to edit your question to make your QnA relevant.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.