android.Settings.Secure.ANDROID_ID

前端之家收集整理的这篇文章主要介绍了android.Settings.Secure.ANDROID_ID前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在开发一个 Android应用程序,我将使用LVL库来检查Google Play许可证.

阅读LVL文档后,我已经看到我必须获取android.Settings.Secure.ANDROID_ID以模糊谷歌播放响应.

但是我也读到从TelephonyManager获得的ANDROID_ID有时是不同的设备相同的.

First,it is not 100% reliable on releases of Android prior to 2.2 (“Froyo”). Also,there has been at least one widely-observed bug in a popular handset from a major manufacturer,where every instance has the same ANDROID_ID

真的吗?

谢谢

解决方法

考虑我的情况:

Same serial number on several android devices. Adb is useless. How can I change the serial number?

所以我没有解决ADB的问题,而是识别一个Android设备我使用这个代码(使用getDeviceId(上下文)):

public static String getDeviceId(Context context) {
    String id = getUniqueID(context);
    if (id == null)
        id = Settings.Secure.getString(context.getContentResolver(),Settings.Secure.ANDROID_ID);
    return id;
}

private static String getUniqueID(Context context) {

    String telephonyDeviceId = "NoTelephonyId";
    String androidDeviceId = "NoAndroidId";

    // get telephony id
    try {
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        telephonyDeviceId = tm.getDeviceId();
        if (telephonyDeviceId == null) {
            telephonyDeviceId = "NoTelephonyId";
        }
    } catch (Exception e) {
    }

    // get internal android device id
    try {
        androidDeviceId = android.provider.Settings.Secure.getString(context.getContentResolver(),android.provider.Settings.Secure.ANDROID_ID);
        if (androidDeviceId == null) {
            androidDeviceId = "NoAndroidId";
        }
    } catch (Exception e) {

    }

    // build up the uuid
    try {
        String id = getStringIntegerHexBlocks(androidDeviceId.hashCode())
                + "-"
                + getStringIntegerHexBlocks(telephonyDeviceId.hashCode());

        return id;
    } catch (Exception e) {
        return "0000-0000-1111-1111";
    }
}

public static String getStringIntegerHexBlocks(int value) {
    String result = "";
    String string = Integer.toHexString(value);

    int remain = 8 - string.length();
    char[] chars = new char[remain];
    Arrays.fill(chars,'0');
    string = new String(chars) + string;

    int count = 0;
    for (int i = string.length() - 1; i >= 0; i--) {
        count++;
        result = string.substring(i,i + 1) + result;
        if (count == 4) {
            result = "-" + result;
            count = 0;
        }
    }

    if (result.startsWith("-")) {
        result = result.substring(1,result.length());
    }

    return result;
}

在使用Web服务时,我可以使用它来识别特定的应用安装.您可以看到我尝试不同的审批,也基于TelephonyManager和ANDROID_ID.

我得到的是像xxxx-xxxx-xxxx-xxxx这样的字符串,其中x是一个十六进制字符.

我买了很多低成本的中国平板电脑,所有这些都具有相同的DEVICE_ID和相同的序列号!所以我的解决方案现在工作很好

原文链接:/android/312521.html

猜你在找的Android相关文章