Last active
December 27, 2015 10:09
-
-
Save maju6406/7308480 to your computer and use it in GitHub Desktop.
This file contains 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 String getTapjoyDeviceID() | |
{ | |
String udid = null; | |
// Try to get IMEI/MEID. | |
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); | |
if (telephonyManager != null) | |
{ | |
String imei = telephonyManager.getDeviceId(); | |
if (imei != null) | |
udid = imei.toLowerCase(); | |
} | |
// Invalid UDID, try to get serial. | |
if (udid == null || udid.length() == 0) | |
{ | |
String id = getSerialID(); | |
if (id != null) | |
udid = id.toLowerCase(); | |
} | |
return udid; | |
} | |
public String getAndroidID() | |
{ | |
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); | |
} | |
public String getSerialID() | |
{ | |
String serial = null; | |
try | |
{ | |
// android.os.Build.SERIAL | |
Class<?> clazz = Class.forName("android.os.Build"); | |
Field field = clazz.getDeclaredField("SERIAL"); | |
if (field.isAccessible() == false) | |
field.setAccessible(true); | |
serial = field.get(android.os.Build.class).toString(); | |
} | |
catch (Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
return serial; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment