Android 获取惟一机器码的代码

作应用时不少时候都得获取到每一个设备的机器码android

  1. Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID)
    或者
    全部的设备均可以返回一个TelephonyManager.getDeviceId()
    全部的GSM设备能够返回一个TelephonyManager.getSimSerialNumber()
    全部的CDMA 设备对于 getSimSerialNumber() 却返回一个空值!
    全部添加有谷歌帐户的设备能够返回一个 ANDROID_ID
    全部的CDMA设备对于 ANDROID_ID 和 TelephonyManager.getDeviceId() 返回相同的值(只要在设置时添加了谷歌帐户)
    正常状况下,你想获得设备的惟一序号, TelephonyManager.getDeviceId() 就足够了。
    但会暴露DeviceID,最好把这些id加密。加密后的序号仍然能够惟一的识别该设备,
    例如,使用 String.hashCode() ,结合UUID:
    ide

  2. final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
    ui

  3. final String tmDevice, tmSerial, tmPhone, androidId;
    加密

  4. tmDevice = "" + tm.getDeviceId();
    spa

  5. tmSerial = "" + tm.getSimSerialNumber();
    orm

  6. androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
    get

  7. UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
    hash

  8. String uniqueId = deviceUuid.toString();
    import

  9. 最后的deviceID多是这样的结果: 00000000-54b3-e7c7-0000-000046bffd97im

相关文章
相关标签/搜索