-1

i have an app, and the scenario is that a password is required to access app for first time. Now when someone has used the password than that password can only be used on that phone again if they uninstall the app or something, just like any software installation on windows which come with unique key.

I was using device ID like

TelephonyManager manager=(TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
 String deviceid=manager.getDeviceId();

But I have received few complaints from users that when they change sim or anything than it asks for a password again and old password doesn't work. I tried to test it and it turns out that on most of device the device id changes with change of sim. I didn't do much reserach before, but now I have read most of qestions and it seems like this id also changes when we factory reset the phone. Now can anyone tell me what is the best way to get the uniquely identify the android devices?

And yes, it is a duplicate of Is there a unique Android device ID? but that doesn't provide me an asnwer as Joe used device id and I have told you what is the problem with using device id, it is changing with change of SIM card.

Thank you

Community
  • 1
  • 1
Hamza
  • 1,593
  • 2
  • 19
  • 31
  • 2
    possible duplicate of [Is there a unique Android device ID?](http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id) – Jan Aug 03 '15 at 13:16
  • *"just like any software installation on windows which come with unique key"* Unless piracy. Or change Windows key. – m0skit0 Aug 03 '15 at 13:17

2 Answers2

0

check for this

String uniqueId=Secure.getString(getContentResolver(),Secure.ANDROID_ID);
Ravi
  • 34,851
  • 21
  • 122
  • 183
  • http://stackoverflow.com/a/4799610/1832135 here it says "Can change upon factory reset" – Hamza Aug 03 '15 at 13:25
0

From how you describe your problem, you really do not need to uniquely identify devices. Your requirements seem to indicate that you only need to uniquely identify installations, since you mentioned that they can use the same password again if they uninstall the app.

This Android Developers blog post explores the topic of identifying devices and installations in a good amount of depth, and provides a solution for identifying installations instead of devices.

All you really need to do is use UUID.randomUUID() to generate an installation ID and persist that ID somewhere. When your users uninstall the app, that ID will be wiped and you can create a new one if they come back.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
  • Consider this scenario, I use a password and send UUID of my device with that, now the password is utilized I store that unique UUID with that password. Now when I uninstall and reinstall that app, it will ask for the password, I should be able to reuse my old password, but now will I receive the same old UUID? If the password is used I check if it was used by same device, if yes than I authorize it otherwise not. I am basically selling passwords with the app. – Hamza Aug 03 '15 at 13:40
  • Using a unique device identifier as a username doesn't sound like a great idea. I obviously don't know your specific use case, but what if your user gets a new device and wants to use the same "account?" No truly unique device ID will allow them to do so. An ID that the user can take between installations or between devices (e.g. email, phone number, username) can be tied to a unique installation ID (or device ID, if that's the route you want to go), solving both problems. – Bryan Herbst Aug 03 '15 at 13:42
  • No, the password is tied to the device, if he changes his phone, he will have to get a new one and thats what we have told them. So, thats fine for now. We are testing it on different users who can't even operate mobile phones, so if we add a new parameter with password, this seem to complicate things a bit, first we will need to explain what is "Email". Considering we can only use a unique id, something that I automatically pick, what is the best one to use that doesn't change? Definitely not Device Id, how about Secure.Android_ID? or the one you mentioned? UUID? will it remain same?? Thanks – Hamza Aug 03 '15 at 16:41
  • The method for generating UUIDs that I demonstrated is random, and depending on how you store it will almost certainly not have the lifecycle you want. `Secure.ANDROID_ID` is generally a good choice, but as the blog post mentions there has been at least one instance of a manufacturer breaking it in the past. – Bryan Herbst Aug 03 '15 at 16:44