Perfect unique_id for device except IMEI,Android_ID,WLAN Mac and Bluetooth address
Asked Answered
C

3

14

Objective:

I am looking for a way to find out a unique_id for android device.

Background:

I will use the Id in login request payload and as my app is license based service app the Id should not change under normal circumstances.

Existing Approaches:

In iOS there are some unique id solutions for iOS such as CFUUID or identifierForVendor coupled with Keychain,Advertising Identifier etc.. that can do this job upto the expectation.

But in Android all the options that I know seems to have hole in it.

IMEI:

TelephonyManager TelephonyMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); 
String m_deviceId = TelephonyMgr.getDeviceId();

Drawbacks

It is sim card dependent so

  • If there is no sim card then we're doomed

  • If there is dual sim then we're dommed

Android_ID:

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

Drawbacks

  • If OS version is upgraded then it may change
  • If device is rooted it gets changed
  • No guarantee that the device_id is unique there are some reports some manufacturers are having duplicate device_id

The WLAN MAC Address

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

Drawbacks

  • If there is no wifi hardware then we're doomed
  • In some new devices If wifi is off then we're doomed.

Bluetooth Address:

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

Drawbacks:

  • if there is no bluetooth hardware we're doomed.
  • In future in some new devices we mightn't able to read it if its off.

Possible solutions:

There are two approaches that I think to solve this problem

  • We generate a random id by hashing timestamp with unique ids that I have mentioned and store it so next time during login we’ll check if the the stored value of key is null if its so then we’ll generate and store it else we’ll use the value of the key.

    If there is something equivalent to keychain of iOS then we’re good with this approach.

  • Find a global identifier something like advertisingIdentifier of iOS which is same for all the apps in the device.

Any help is appreciated !

Cage answered 1/12, 2014 at 17:7 Comment(4)
Ok nice. I read your question, upvoted and favorited. You asked this 4+months ago with no real response. I am not sure the BEST way to handle iOS + Android unique Ids. That is taking it to the next level. I would use something seamless by now, like "Sign in with Google" using OAuth. This way it works on both iOS and Android or Web devices.Cattier
@JaredBurrows - Does OAuth provide tracking an individual device ? I provide device quota per user. i.e A user can maximum use one account in three devicesCage
@DuraiAmuthan.H, i have read a comment of yours below. You say that your are app is wifi depended and you need a unigue device identifier. Therefore i think mac address is the best option. I pretty much facing the same problem right now and am between AndroidUUID and MacAddress. Do you have anything to add after using AndroidUUID? Thanks.Cumulate
I am using Android_ID as its not dependent on any hardware while mac address does depend on WifiCage
C
7

I have chosen to use Android_ID since It's not dependent on any hardware.

Build.SERIAL also dependent on availability of telephony that is in wifi only devices this Build.SERIAL won't work.

I have explained how other approaches are dependent upon the hardware availability in the question itself.

Cage answered 23/7, 2015 at 7:53 Comment(5)
This android-developers.googleblog.com/2011/03/… explains some problems with using Android_ID . Specifically, it is not 100% reliable on releases of Android prior to 2.2 (“Froyo”). Also, there has been at least one widely-observed bug in a popular handset from a major manufacturer, where every instance has the same ANDROID_ID.Willable
@Willable You do realize that no one is using Froyo anymore, that the blog entry is from 2011 (6 years ago) and that the device they happen to be referring about is the Samsung Galaxy, right? You would be lucky to find one still working nowadays, lol.Gerfalcon
@Gerfalcon oh don't we wish that was the case :-( . Unfortunately it still exists, and there are many who cannot and will not get timely updates, so... ¯_(ツ)_/¯Willable
Ehmmm... Our App has more than 17 million downloads in more than 14 countries and I have yet to find a duplicated or null ANDROID_ID in our DB... Maybe in theory it can happen, but in practice I have more than enough data to prove that post outdated ¯_(ツ)_/¯Gerfalcon
@Gerfalcon - Thanks for sharing the infoCage
J
1

There is no such ID available on Android. You can generate your own, for example a random UUID and connect it to the user's account. This is what Kindle, Audible and other applications do to identify devices in a non-privacy-intrusive way.

Consider Google Analytics Mobile if you want to "track your users", http://www.google.com/analytics/mobile/

If you want to get closer to tracking a device you can combine the IDs above together in a hash-function. Bluetooth + wifi + android serial, and if any of them are null, you put a 0 in the hash, e.g. if there is no wifi mac addr. As you point out, you aren't guaranteed the id won't change. Unless the user is running a custom ROM, I would expect this computed ID to stay constant, though.

Jackal answered 1/12, 2014 at 17:30 Comment(5)
Computed Ids doesn't suit my application.Because If the app in uninstalled and the Id is gone then I am doomed.Cage
@Duraiamuthan.H the hashing method is stable and will be the same across app reinstalls. It may change on ROM-reinstall/change though!Jackal
if app is uninstalled how the value will persist..The hash value may change depending upon wifi/Bluetooth status and availability during the app reinstallation.Cage
@Duraiamuthan.H no problem, the hash function gives the same result each time it is executed, imagine id = f(wifi_mac, bluetooth_mac, android_id). The id will always be the same for the same inputs. You can use this class for the hashing docs.oracle.com/javase/7/docs/api/java/security/…Jackal
You are right if input is same each time it will give the same hash But there is some possibility that input might change for instance the wifi_mac returns null if wifi is off in some latest devices and Bluetooth_mac also may experience the same problem in upcoming versions and android_id is not unique after all there are complaints that these are duplicatedCage
V
1

I think, you could use device serial ID (hardware serial number, not android id). You could seen it in device settings. In your code, you could get it by Build.SERIAL.

Vanvanadate answered 2/12, 2014 at 11:1 Comment(4)
one upvote for pointing out Build.Serial.But Devices without telephony doesn't have Build.Serial.It'll be a problem for me as my app will be used in wifi only devices.Build.Serial is available from API 9 or 2.3 gingerbread But its not a problem for me as my app is going to target 4.0 above.Cage
@Duraiamuthan.H I think al devices have a "serial" but not all devices an "IMEI" number.Cattier
@JaredBurrows - I am not sure all devices have Build.Serial somewhere I read If the device doesn't have telephony then there would be no build.serial for that device e.g consider wifi only devices .Can you confirm it.Cage
@DuraiAmuthan.H You want me to confirm something that you read ? You are right about build.serial: developer.android.com/reference/android/os/Build.html#SERIAL. I have updated my post with more information. I say you must choose software vs hardware(most likely software to track users between devices).Cattier

© 2022 - 2024 — McMap. All rights reserved.