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性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...