【问题标题】:How to get the MAC Address of any android phone?如何获取任何安卓手机的MAC地址?
【发布时间】:2017-02-02 02:08:37
【问题描述】:

我在LINK 上看到了如何获取安卓手机的 MAC 地址,但在我的情况下,我需要在 javascriptasp.net mvc3 中进行操作。我设法通过MVC3 获得了PC 的MAC Address,我的问题1 已解决。这是我在安卓手机中遇到的第二个问题。

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

【问题讨论】:

    标签: javascript android macos asp.net-mvc-3 mac-address


    【解决方案1】:

    在 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

    【讨论】:

      猜你喜欢
      • 2012-07-15
      • 2014-02-03
      • 1970-01-01
      • 2011-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-06
      • 2012-10-11
      相关资源
      最近更新 更多