Skip to content

Instantly share code, notes, and snippets.

@maju6406
Last active December 27, 2015 10:09
Show Gist options
  • Save maju6406/7308480 to your computer and use it in GitHub Desktop.
Save maju6406/7308480 to your computer and use it in GitHub Desktop.
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