Skip to content

Instantly share code, notes, and snippets.

@ruan65
Created October 9, 2016 16:18
Show Gist options
  • Save ruan65/6b8b24e811a00a7dbf373830d20148f4 to your computer and use it in GitHub Desktop.
Save ruan65/6b8b24e811a00a7dbf373830d20148f4 to your computer and use it in GitHub Desktop.
Get android device 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);
}
Timber.i("device id: %s", deviceId);
return deviceId;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment