携带获取失败处理

 /**
     * 当前的mac地址
     *
     * @return String mac
     */
    @SuppressLint("HardwareIds")
    private static String getMacAddress() {
        try {
            WifiManager wifiMan = (WifiManager) MyApplication.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
            assert wifiMan != null;
            WifiInfo info = wifiMan.getConnectionInfo();
            String mac = "";
            if (null != info) {
                mac = (info.getMacAddress()).replaceAll(":", "-");
            }
            return defaultMac(mac);
        } catch (Exception ignored) {
        }
        return defaultMac("");
    }

    private static String defaultMac(String mac) {
        if ("".equals(mac) || mac == null) {
            return "02:00:00:00:00:00";
        } else {
            return mac;
        }
    }

项目使用截图 

android mac获取(已经上线使用三年)

相关文章:

  • 2021-09-12
  • 2021-11-19
  • 2021-11-19
  • 2022-01-07
  • 2021-10-15
  • 2021-06-30
  • 2022-12-23
  • 2021-10-14
猜你喜欢
  • 2021-10-18
  • 2021-07-13
  • 2021-08-15
  • 2022-01-05
  • 2021-11-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案