Created
October 8, 2016 15:50
-
-
Save ruan65/1fae636547913d58cbadd3c8d73625a2 to your computer and use it in GitHub Desktop.
Get Android device unique 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); | |
} | |
return deviceId; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment