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();

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐