Created
January 30, 2016 12:00
-
-
Save milaptank/25eddae25b59c643eb19 to your computer and use it in GitHub Desktop.
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
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
import android.content.Context; | |
import android.net.wifi.WifiManager; | |
import android.os.Build; | |
import android.provider.Settings.Secure; | |
import android.telephony.TelephonyManager; | |
public class UDID { | |
public UDID() { | |
} | |
public String getUDID(Context c) { | |
// Get some of the hardware information | |
String buildParams = Build.BOARD + Build.BRAND + Build.CPU_ABI | |
+ Build.DEVICE + Build.DISPLAY + Build.FINGERPRINT + Build.HOST | |
+ Build.ID + Build.MANUFACTURER + Build.MODEL + Build.PRODUCT | |
+ Build.TAGS + Build.TYPE + Build.USER; | |
// Requires READ_PHONE_STATE | |
TelephonyManager tm = (TelephonyManager) c | |
.getSystemService(Context.TELEPHONY_SERVICE); | |
// gets the imei (GSM) or MEID/ESN (CDMA) | |
String imei = tm.getDeviceId(); | |
// gets the android-assigned id | |
String androidId = Secure.getString(c.getContentResolver(), | |
Secure.ANDROID_ID); | |
// requires ACCESS_WIFI_STATE | |
WifiManager wm = (WifiManager) c.getSystemService(Context.WIFI_SERVICE); | |
// gets the MAC address | |
String mac = wm.getConnectionInfo().getMacAddress(); | |
// concatenate the string | |
String fullHash = buildParams + imei + androidId + mac; | |
return md5(fullHash); | |
} | |
public String md5(String toConvert) { | |
String retVal = ""; | |
MessageDigest algorithm; | |
try { | |
algorithm = MessageDigest.getInstance("MD5"); | |
algorithm.reset(); | |
algorithm.update(toConvert.getBytes()); | |
byte messageDigest[] = algorithm.digest(); | |
StringBuffer hexString = new StringBuffer(); | |
for (int i = 0; i < messageDigest.length; i++) { | |
hexString.append(Integer.toHexString(0xFF & messageDigest[i])); | |
} | |
retVal = hexString + ""; | |
} catch (NoSuchAlgorithmException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
return retVal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment