This is just to elaborate on the answer by @MikeLaren, which is correct. But there are a couple of gotchas to be aware of, as documented in the following code, which is what I'm currently using:
// Get the unique (supposedly) ID for this Android device/user combination
long androidId = convertHexToLong(Settings.Secure.getString(
_applicationContext.getContentResolver(), Settings.Secure.ANDROID_ID));
....
// Method to convert a 16-character hex string into a Java long. This only took me about an hour,
// due to a known bug in Java that it took them 13 years to fix, and still isn't fixed in the
// version of Java used for Android development.
// http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4215269
// http://stackoverflow.com/questions/1410168/how-to-parse-negative-long-in-hex-in-java
// On top of that it turns out that on a HTC One the Settings.Secure.ANDROID_ID string may be 15
// digits instead of 16!
private long convertHexToLong(String hexString) {
hexString = "0000000000000000" + hexString;
int i = hexString.length();
hexString = hexString.substring(i - 16, i);
try {
return Long.parseLong(hexString.substring(0, 8), 16) << 32 |
Long.parseLong(hexString.substring(8, 16), 16);
} catch (Exception e) {
return 0L;
}
}