第一种:SIM卡唯一标识 + DEVICE_ID(根据不同的手机设备返回IMEI,MEID或者ESN码)+androidId

这种方式获取的UUID是唯一不可变的,但是仅适用于手机中有SIM卡的情况。

private String getMyUUID(){

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

  final String tmDevice, tmSerial, tmPhone, androidId;   

  tmDevice = "" + tm.getDeviceId();  

  tmSerial = "" + tm.getSimSerialNumber();   

 androidId= "" + android.provider.Settings.Secure.getString(getContentResolver(),

     android.provider.Settings.Secure.ANDROID_ID);   

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

  String uniqueId = deviceUuid.toString();

  Log.d("debug","uuid="+uniqueId);

  return uniqueId;

 }

第二种:这种方式获取的UUID是可变的,但是可以适用于各种形式。 

private String getMyUUID(){

  UUID uuid = UUID.randomUUID();

     String uniqueId = uuid.toString();

   Log.d("debug","----->UUID"+uuid);

    return uniqueId;

   }

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐