Created
October 9, 2016 16:18
-
-
Save ruan65/6b8b24e811a00a7dbf373830d20148f4 to your computer and use it in GitHub Desktop.
Get android device id
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 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