android 生成唯一guid,android - Android_id to guid? - Stack Overflow
I am using Secure.Android_Id for getting unique id of the device. But I need to pass it to as GUID for a service. Is there a easy way to create that?The basic code I wrote looks something like this:St
I am using Secure.Android_Id for getting unique id of the device. But I need to pass it to as GUID for a service. Is there a easy way to create that?
The basic code I wrote looks something like this:
String android_id = getAndroidId();
long leastSignificantBits = 0;
long mostSignificantBits = 0;
UUID uuid = null;
if (android_id != null) {
String asciiConvertedText = "";
int len = android_id.length();
for (int i = 0; i < len; i++) {
asciiConvertedText += "" + ((short) android_id.charAt(i));
}
len = asciiConvertedText.length();
if (len > 16) {
leastSignificantBits = Long.parseLong(asciiConvertedText.substring(0, 15));
if (asciiConvertedText.length() > 31) {
mostSignificantBits = Long.parseLong(asciiConvertedText.substring(16, 31));
} else {
mostSignificantBits = Long.parseLong(asciiConvertedText.substring(32,
asciiConvertedText.length()));
}
uuid = new UUID(mostSignificantBits, leastSignificantBits);
} else if (len > 0) {
leastSignificantBits = Long.parseLong(asciiConvertedText);
uuid = new UUID(mostSignificantBits, leastSignificantBits);
} else {
uuid = UUID.randomUUID();
}
}
if (uuid != null) {
deviceUUID = uuid.toString();
}
更多推荐


所有评论(0)