Android_id到的GUID? [英] Android_id to guid?

查看:577
本文介绍了Android_id到的GUID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Secure.Android_Id获取设备的唯一的ID。但我需要将它传递给作为GUID的服务。有没有一种简单的方法来创建?

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?

基本code我写了看起来像这个

The basic code I wrote looks something like this:


            串android_id = getAndroidId();
        长leastSignificantBits = 0;
        长mostSignificantBits = 0;
        UUID UUID = NULL;

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

推荐答案

如何新的UUID(Secure.Android_Id.hash code(),Secure.Android_Id.hash code( )

编辑:这是我的code为独一无二的ID:

Edited: here's my code for "unique" 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();
}

我不知道如果上述可以帮助你,但我用几个值的复合(我想我在这里另一个线程上这个计算器code)。

I'm not sure if the above helps you, but I use a composite of several values (I think I got this code from another thread here on stackoverflow).

这篇关于Android_id到的GUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆