Skip to content

Instantly share code, notes, and snippets.

@pcqpcq
Last active May 25, 2017 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcqpcq/d85b79c590e758bf58101a94480d1b45 to your computer and use it in GitHub Desktop.
Save pcqpcq/d85b79c590e758bf58101a94480d1b45 to your computer and use it in GitHub Desktop.
any possible ways to get an android id outside the world.
// #region from [here](https://github.com/nisrulz/easydeviceinfo/blob/develop/easydeviceinfo-base/src/main/java/github/nisrulz/easydeviceinfo/base/EasyIdMod.java)
/**
* Gets android id.
*
* @return the android id
*/
@SuppressLint("HardwareIds")
public final String getAndroidID() {
return CheckValidityUtil.checkValidData(
Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID));
}
/**
* Gets psuedo unique id.
*
* @return the psuedo unique id
*/
@SuppressWarnings("deprecation")
public final String getPseudoUniqueID() {
// If all else fails, if the user does have lower than API 9 (lower
// than Gingerbread), has reset their phone or 'Secure.ANDROID_ID'
// returns 'null', then simply the ID returned will be solely based
// off their Android device information. This is where the collisions
// can happen.
// Try not to use DISPLAY, HOST or ID - these items could change.
// If there are collisions, there will be overlapping data
String devIDShort = "35" + (Build.BOARD.length() % 10) + (Build.BRAND.length() % 10);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
devIDShort += (Build.SUPPORTED_ABIS[0].length() % 10);
}
else {
devIDShort += (Build.CPU_ABI.length() % 10);
}
devIDShort +=
(Build.DEVICE.length() % 10) + (Build.MANUFACTURER.length() % 10) + (Build.MODEL.length()
% 10) + (Build.PRODUCT.length() % 10);
// Only devices with API >= 9 have android.os.Build.SERIAL
// http://developer.android.com/reference/android/os/Build.html#SERIAL
// If a user upgrades software or roots their phone, there will be a duplicate entry
String serial;
try {
serial = Build.class.getField("SERIAL").get(null).toString();
// Go ahead and return the serial for api => 9
return new UUID(devIDShort.hashCode(), serial.hashCode()).toString();
} catch (Exception e) {
// String needs to be initialized
if (EasyDeviceInfo.debuggable) {
Log.e(EasyDeviceInfo.nameOfLib, "getPseudoUniqueID: ", e);
}
serial = "ESYDV000"; // some value
}
// Finally, combine the values we have found by using the UUID class to create a unique identifier
return new UUID(devIDShort.hashCode(), serial.hashCode()).toString();
}
// endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment