Milad Nouri
Milad Nouri

Reputation: 1597

Android - unique and constant device ID

I need to register user devices on server with an unique identifier that be a constant value and doesn't change in the future.

I can't find a good solution to get unique id from all devices (with/without simcard).

Secure.ANDROID_ID: Secure.ANDROID_ID is not unique and can be null or change on factory reset.

String m_androidId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

IMEI: IMEI is dependent on the Simcard slot of the device, so it is not possible to get the IMEI for the devices that do not use Simcard.

TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uuid = tManager.getDeviceId();

WLAN MAC Address: If device doesn’t have wifi hardware then it returns null MAC address. and user can change the device mac address.

WifiManager m_wm = (WifiManager)getSystemService(Context.WIFI_SERVICE); 
String m_wlanMacAdd = m_wm.getConnectionInfo().getMacAddress();

Bluetooth Address string:If device hasn’t bluetooth hardware then it returns null.

BluetoothAdapter m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
String m_bluetoothAdd = m_BluetoothAdapter.getAddress();

Instance id: instance_id will change when user uninstalls and reinstalls app. and it's not a constant value.

Do you have any idea to get a unique id from all Android devices (with/without simcard, Bluetooth, ...) that really be unique, cannot be null and doesn't change after uninstall/reinstall app?

Upvotes: 16

Views: 9063

Answers (4)

Kushal
Kushal

Reputation: 1

I need to register user devices on server with an unique identifier that be a constant value and doesn't change in the future.

I can't find a good solution to get unique id from all devices (with/without simcard).

Secure.ANDROID_ID: Secure.ANDROID_ID is not unique and can be null or change on factory reset.

String m_androidId = Secure.getString(getContentResolver(), Secure.ANDROID_ID); IMEI: IMEI is dependent on the Simcard slot of the device, so it is not possible to get the IMEI for the devices that do not use Simcard.

Upvotes: 0

Milad Nouri
Milad Nouri

Reputation: 1597

I found that Secure.ANDROID_ID is the best choice. This is a 64-bit quantity that is generated and stored when the device first boots. But it resets on device factory reset.

there are some reports that shows some devices has same Secure.ANDROID_ID on all instances.

we can add extra items (like sim serial, GCM instance id or ...) to the Secure.ANDROID_ID and generate new unique fingerprint.

Upvotes: 4

user4626796
user4626796

Reputation: 61

Mutiple users can be setup on Android device and Secure.ANDROID_ID is different for every user on same Android device. So using Secure.ANDROID_ID means single devices will be registered as a different device for each user setup on the device.

Upvotes: 3

userM1433372
userM1433372

Reputation: 5517

Secure.ANDROID_ID is your only friend. However it has some problems (empty results) on older (<2.3) devices. All other ID's do not work on all type of devices.

Please also read Is there a unique Android device ID?

Upvotes: 0

Related Questions