-1

I am creating a user based android application wherein each user will be registered with a unique id when he/she will be signing up for the first time. How do I do it?

Parita Patel
  • 82
  • 2
  • 8

3 Answers3

1

For Device id

String android_id = Settings.Secure.getString(getContext().getContentResolver(),
                    Settings.Secure.ANDROID_ID);
Nisarg
  • 1,358
  • 14
  • 30
  • It's known to be null sometimes, it's documented as "can change upon factory reset". Use at your own risk, and it can be easily changed on a rooted phone – MilapTank Jan 30 '16 at 10:42
  • But we can set constraint for null values , there will be no risk i guess for rooted devices too – Nisarg Jan 30 '16 at 10:49
  • if we are making ANDROID_ID as primary key than same user can make more than one account from one device this is only risk :) – MilapTank Jan 30 '16 at 10:52
  • Yea true , thank you for information means we can not overcome this problem right !! for rooted devices – Nisarg Jan 30 '16 at 11:02
  • 1
    No friend you can use other technique for this i have use in my project that you can see this https://gist.github.com/milaptank/25eddae25b59c643eb19 :) – MilapTank Jan 30 '16 at 12:02
  • Thank you, I'll use too whenever require – Nisarg Jan 30 '16 at 12:07
1

If the ID doesn't need to be regeneratable (e.g. when the user signs in from the new phone) then just use a UUID.

It will be based on the current time and the Hardware ID of the network adapter (wifi)

hardillb
  • 54,545
  • 11
  • 67
  • 105
1

Starting with Java 5 there is a UUID (Unique identifier) class. So just do something like this:

UUID userId = UUID.randomUUID();

And you will have a Unique ID for that session that you can store.