Created
December 16, 2011 10:13
-
-
Save nikreiman/1485468 to your computer and use it in GitHub Desktop.
Hairy-ish code for getting unique ID from Android device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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