【问题标题】:Android get unique id for deviceAndroid获取设备的唯一ID
【发布时间】:2019-05-19 12:22:01
【问题描述】:

我需要将每个用户的应用订阅限制为一定数量的设备。为此,我试图获取 android 手机(硬件)的唯一 ID。我发现了以下选项,但它们都有某些问题。有没有没有这些问题的解决方案?

  • 使用 TelephonyManager API (getDeviceId) 的 Imei / Mei 号码 - 如果双 sim 卡可能存在活动和非活动 sim 插槽,这将是一个问题。
  • AndroidId - 将在出厂重置时重置
  • Wifi mac 号码 - 需要连接 wifi 才能获取此号码,对于非 wifi 设备,此号码将不存在。
  • Advertaising id - 可由用户重置
  • Instance id - 可以恢复出厂设置
  • Sim serial number - 不绑定到设备,而是用于 sim

【问题讨论】:

  • “有没有没有这些问题的解决方案?”——没有,因为硬件标识符引发了太多隐私问题。
  • 实现这个逻辑的最佳方式是什么?
  • 想出一种商业模式,不需要您将应用订阅限制为每个用户特定数量的设备。例如,您可以按设备收费,在这种情况下,您会希望用户拥有很多设备。

标签: android telephonymanager


【解决方案1】:

经过搜索和思考,我想出了以下解决方案。

MacID 可以用作唯一标识。即使在 Wifi 关闭状态下,也可以使用权限 android.permission.READ_PHONE_STATE 获取 MacID。我已经在少数设备上成功地测试了这些,并且效果很好。我的测试正在进行中,很快就会在这里更新。

public static String getDeviceMacId(){
        try {
            List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
            for (NetworkInterface nif : all) {
                if (!nif.getName().equalsIgnoreCase("wlan0")) continue;

                byte[] macBytes = nif.getHardwareAddress();
                if (macBytes == null) {
                    return "";
                }

                StringBuilder res1 = new StringBuilder();
                for (byte b : macBytes) {
                    res1.append(String.format("%02X:",b));
                }

                if (res1.length() > 0) {
                    res1.deleteCharAt(res1.length() - 1);
                }
                return res1.toString();
            }
        } catch (Exception ex) {
            //handle exception
        }
        return "";
    }



参考:https://stackoverflow.com/a/35830358/2788009

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-07
    • 1970-01-01
    • 2019-08-28
    • 1970-01-01
    • 1970-01-01
    • 2020-06-15
    • 1970-01-01
    相关资源
    最近更新 更多