Skip to content

Instantly share code, notes, and snippets.

@nikreiman
Created December 16, 2011 10:13
Show Gist options
  • Save nikreiman/1485468 to your computer and use it in GitHub Desktop.
Save nikreiman/1485468 to your computer and use it in GitHub Desktop.
Hairy-ish code for getting unique ID from Android device
public String getUniqueId(final Context context) {
String uniqueId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
// Ugh, Motorola's Droid 2.2 devices return this ID, which they copied directly from the Android emulator. If
// we see that device ID, we should instead use the telephony manager's ID instead.
if(uniqueId == null || uniqueId.equals("9774d56d682e549c")) {
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
uniqueId = telephonyManager.getDeviceId();
}
if(uniqueId == null) {
ErrorController.logErrorRemotely("No unique ID found for device!", null);
}
return uniqueId;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment