几个月来,我一直在使用一个类来生成一个在重新安装之间保持不变的UUID。我的应用程序是关于折扣的,所以我依靠这个UUID来限制每个设备上的优惠券数量。
protected void getDeviceId(){
try {
Context context = cordova.getActivity().getApplicationContext();
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String uuid;
String androidID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
String deviceID = tm.getDeviceId();
String simID = tm.getSimSerialNumber();
if ("9774d56d682e549c".equals(androidID) || androidID == null) {
androidID = "";
}
if (deviceID == null) {
deviceID = "";
}
if (simID == null) {
simID = "";
}
uuid = androidID + deviceID + simID;
uuid = String.format("%32s", uuid).replace(' ', '0');
uuid = uuid.substring(0, 32);
uuid = uuid.replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5");
this.callbackContext.success(uuid);
}catch(Exception e ) {
this.callbackContext.error("Exception occurred: ".concat(e.getMessage()));
}
}
那就是我生成uuid的核心。问题是,这个周末有人使用XT1032和Android 5.1,在每次安装应用程序后都能够重新生成不同的UUID,并获得免费优惠券。我使用的这种方法可能会被欺骗吗?也许用一个rooted手机?我一无所知。我需要能够在安装之间创建可靠的UUID。