如何获取任何安卓手机的MAC地址



我已经看到了这个关于如何获取安卓手机MAC地址的链接,但就我而言,我需要在javascriptasp.net mvc3中执行此操作。我设法通过MVC3获得了PC的MAC Address,我的问题1解决了。这是我在安卓手机中的第二个问题。

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String macAddress = wInfo.getMacAddress(); 
有一个

解决方法可以在Android 6.0中获取Mac地址。

首先,您需要添加互联网用户权限。

然后,您可以通过NetworkInterfaces API找到Mac。

public static String getMacAddr() {
  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) {
  }
  return "02:00:00:00:00:00";
}

来源: http://robinhenniges.com/en/android6-get-mac-address-programmatically

最新更新