Skip to content

Instantly share code, notes, and snippets.

@ruan65
Created October 8, 2016 15:50
Show Gist options
  • Save ruan65/1fae636547913d58cbadd3c8d73625a2 to your computer and use it in GitHub Desktop.
Save ruan65/1fae636547913d58cbadd3c8d73625a2 to your computer and use it in GitHub Desktop.
Get Android device unique id
public static String getDeviceId(Context ctx) {
TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
String deviceId;
if (tm.getDeviceId() != null) {
deviceId = tm.getDeviceId();
} else {
deviceId = Settings.Secure.getString(
ctx.getApplicationContext().getContentResolver(),
Settings.Secure.ANDROID_ID);
}
return deviceId;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment