I was working on an app (server-android client) that allow user to sign in from multiple android devices. When user logged in on a device, that device will be registered on server side, but I don't know how to avoid duplicate, so I was wondering that are there any chances to uniquely identify an android device? I think Google Play and Facebook can do that.
There are several options available, but there is no 100% guarantee that they will always work. See the android developer blog post: http://android-developers.blogspot.in/2011/03/identifying-app-installations.html
Best method mentioned is Settings.Secure.ANDROID_ID
You can check the IMEI
or MAC
address of the device.
for IMEI
TelephonyManager.getDeviceId will work
for MAC
WifiInfo.getMacAddress will work
-
-
1@StinePike I was using the imei. If users use this app play.google.com/store/apps/… then we will get wrong imei. – Prashanth Debbadwar Feb 15 '17 at 6:35
-
2Just a note taken from Android official site:
It is generally not recommended to use MAC address for any form of user identification. As a result, as of Android M, local device MAC addresses (for example, Wifi and Bluetooth) are not available via third party APIs. The WifiInfo.getMacAddress() method and the BluetoothAdapter.getDefaultAdapter().getAddress() method will both return 02:00:00:00:00:00
. – Ankit Shubham Jul 19 '17 at 10:52 -
MAC Address can be fetched through NetworkInterface.getNetworkInterfaces() or DevicePolicyManager. – Stephen M -on strike- Apr 3 '18 at 19:23
-
4