我正在使用 Secure.Android_Id 获取设备的唯一 ID。但我需要将它作为服务的 GUID 传递。有没有简单的方法来创建它?
我写的基本代码看起来像这个:
String android_id = getAndroidId();
long leastSignificantBits = 0;
长最重要位= 0;
UUID uuid = null;
if (android_id != null) {
字符串 asciiConvertedText = "";
int len = android_id.length();
对于 (int i = 0; i < len; i++) {
asciiConvertedText += ""+ ((短) android_id.charAt(i));
}
len = asciiConvertedText.length();
如果(长度 > 16){
leastSignificantBits = Long.parseLong(asciiConvertedText.substring(0, 15));
如果(asciiConvertedText.length()> 31){
mostSignificantBits = Long.parseLong(asciiConvertedText.substring(16, 31));
} 别的 {
mostSignificantBits = Long.parseLong(asciiConvertedText.substring(32,
asciiConvertedText.length()));
}
uuid = new UUID(mostSignificantBits, leastSignificantBits);
}否则如果(len> 0){
leastSignificantBits = Long.parseLong(asciiConvertedText);
uuid = new UUID(mostSignificantBits, leastSignificantBits);
} 别的 {
uuid = UUID.randomUUID();
}
}
如果(uuid!= null){
deviceUUID = uuid.toString();
}
最佳答案
新的 UUID(Secure.Android_Id.hashCode(), Secure.Android_Id.hashCode()
怎么样?
已编辑:这是我的“唯一”ID 代码:
public static String getDeviceId() {
final TelephonyManager tm = (TelephonyManager)Globals.Line2App.getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice, tmSerial, androidId;
tmDevice = "" + tm.getDeviceId();
tmSerial = "" + tm.getSimSerialNumber();
androidId = "" + Secure.getString(Globals.Line2App.getContentResolver(), Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
return deviceUuid.toString();
}
我不确定以上内容是否对您有帮助,但我使用了多个值的组合(我想我是从 stackoverflow 上的另一个线程获得这段代码的)。
关于Android_id 来引导?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4474095/