Android获取设备的唯一id

Android获取设备的唯一id,android,telephonymanager,Android,Telephonymanager,我需要将应用程序订阅限制为每个用户一定数量的设备。为此,我试图获得android手机(硬件)的唯一id。我找到了以下选项,但它们都有一定的问题。有什么解决办法不存在这些问题吗? 使用TelephonyManager API()的Imei/Mei号码-在双sim卡的情况下,可能存在活动和非活动sim卡插槽,这将有问题 -将在工厂重置后重置 Wifi mac号码-需要连接Wifi才能获得此号码,而非Wifi设备将不存在此号码 -可由用户重置 -可在工厂重置时重置 -不绑定到设备,而是针对sim卡

我需要将应用程序订阅限制为每个用户一定数量的设备。为此,我试图获得android手机(硬件)的唯一id。我找到了以下选项,但它们都有一定的问题。有什么解决办法不存在这些问题吗?

  • 使用TelephonyManager API()的Imei/Mei号码-在双sim卡的情况下,可能存在活动和非活动sim卡插槽,这将有问题
  • -将在工厂重置后重置
  • Wifi mac号码-需要连接Wifi才能获得此号码,而非Wifi设备将不存在此号码
  • -可由用户重置
  • -可在工厂重置时重置
  • -不绑定到设备,而是针对sim卡

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

MacID可以用作唯一的id。MacID可以使用permission
android.permission.READ\u PHONE\u STATE
获取,即使在Wifi关闭状态下也是如此。我已经在一些设备上成功地测试了这些功能,效果很好。我的测试正在进行中,很快会在这里更新

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 "";
    }



public静态字符串getDeviceMacId(){
试一试{
List all=Collections.List(NetworkInterface.getNetworkInterfaces());
用于(网络接口nif:all){
如果(!nif.getName().equalsIgnoreCase(“wlan0”))继续;
byte[]macBytes=nif.getHardwareAddress();
if(macBytes==null){
返回“”;
}
StringBuilder res1=新的StringBuilder();
用于(字节b:macBytes){
追加(String.format(“%02X:”,b));
}
如果(res1.length()>0){
res1.deleteCharAt(res1.length()-1);
}
返回res1.toString();
}
}捕获(例外情况除外){
//处理异常
}
返回“”;
}

参考资料:

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

MacID可以用作唯一的id。MacID可以使用permission
android.permission.READ\u PHONE\u STATE
获取,即使在Wifi关闭状态下也是如此。我已经在一些设备上成功地测试了这些功能,效果很好。我的测试正在进行中,很快会在这里更新

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 "";
    }



public静态字符串getDeviceMacId(){
试一试{
List all=Collections.List(NetworkInterface.getNetworkInterfaces());
用于(网络接口nif:all){
如果(!nif.getName().equalsIgnoreCase(“wlan0”))继续;
byte[]macBytes=nif.getHardwareAddress();
if(macBytes==null){
返回“”;
}
StringBuilder res1=新的StringBuilder();
用于(字节b:macBytes){
追加(String.format(“%02X:”,b));
}
如果(res1.length()>0){
res1.deleteCharAt(res1.length()-1);
}
返回res1.toString();
}
}捕获(例外情况除外){
//处理异常
}
返回“”;
}

参考资料:

“有没有解决方案不存在这些问题?”--没有,因为硬件标识符会引发太多隐私问题。我实现这一逻辑的最佳方式是什么?提出一种商业模式,它不要求您将应用程序订阅限制在每个用户特定数量的设备上。例如,你可以按设备收费,在这种情况下,你希望用户拥有大量设备。“有没有解决方案没有这些问题?”--没有,因为硬件标识符会引起太多隐私问题。我能实现此逻辑的最佳方式是什么?提出一种商业模式,该模式不要求您将应用程序订阅限制为每个用户特定数量的设备。例如,您可以按设备收费,在这种情况下,您希望用户拥有大量设备。