Skip to content

Instantly share code, notes, and snippets.

@gotomypc
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gotomypc/e6b7aae9e185656c3010 to your computer and use it in GitHub Desktop.
Save gotomypc/e6b7aae9e185656c3010 to your computer and use it in GitHub Desktop.
public static java.lang.String getDeviceID() {
//1 compute IMEI
TelephonyManager TelephonyMgr = (TelephonyManager)instance.getSystemService(TELEPHONY_SERVICE);
String imei = TelephonyMgr.getDeviceId(); // Requires READ_PHONE_STATE
//2 compute DEVICE ID
String devIDShort = "35" + //we make this look like a valid IMEI
Build.BOARD.length()%10+ Build.BRAND.length()%10 +
Build.CPU_ABI.length()%10 + Build.DEVICE.length()%10 +
Build.DISPLAY.length()%10 + Build.HOST.length()%10 +
Build.ID.length()%10 + Build.MANUFACTURER.length()%10 +
Build.MODEL.length()%10 + Build.PRODUCT.length()%10 +
Build.TAGS.length()%10 + Build.TYPE.length()%10 +
Build.USER.length()%10 ; //13 digits
//3 android ID - unreliable
String androidID = Secure.getString(instance.getContentResolver(), Secure.ANDROID_ID);
//4 wifi manager, read MAC address - requires android.permission.ACCESS_WIFI_STATE or comes as null
WifiManager wm = (WifiManager)instance.getSystemService(Context.WIFI_SERVICE);
String wLANMAC = wm.getConnectionInfo().getMacAddress();
//5 Bluetooth MAC address android.permission.BLUETOOTH required
BluetoothAdapter m_BluetoothAdapter = null; // Local Bluetooth adapter
m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
String bTMAC = m_BluetoothAdapter.getAddress();
//6 SUM THE IDs
String deviceID = imei + devIDShort + androidID + wLANMAC + bTMAC;
return deviceID;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment