Unique device identifier android

0

I have the following problem in my application. On the first boot I get androidID using the following method:

 Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID)

This code is being used to validate in a webservice whether it is the first installation of the application on a particular device.

But when you perform an android recovery, or give it a recovery, that code is raised again, the Google documentation says it is updated every time the system boots.

I need a code that is unique and can not be the IMEI because it does not exist on devices that do not have a chip.

Any suggestions?

    
asked by anonymous 28.06.2016 / 17:01

1 answer

2
Well, unique ID on Android is a bit tricky to have for sure, there are several places that provide an ID and not always the same place is available on all devices, my solution was to create your own ID by combining all the information that I can get.

I use this to control access and honestly I have never had a problem changing (however, it might change if the phone is formatted or changed), so I think it is ideal at the first access to write this ID to a bank in the (which would not change if you changed the SIM), in this case, you would only lose the ID if you formatted the cell phone, which would also trigger a first installation.

Here is the code I use:

 final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);

    final String tmDevice, tmSerial, androidId;
    tmDevice = "" + tm.getDeviceId();
    tmSerial = "" + tm.getSimSerialNumber();
    androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);

    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    String deviceId = deviceUuid.toString();

This code will generate an ID in this format: 00000000-5ff5-17e8-ffff-ffff9d6a7f8f

    
30.06.2016 / 17:55