get Local Mac Address - Android java.net

Android examples for java.net:Mac Address

Description

get Local Mac Address

Demo Code

import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

public class Main {

  public static String getLocalMacAddress(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifi == null) {
      return "";
    }//  ww  w .  j  a v  a  2 s .  com
    WifiInfo info = wifi.getConnectionInfo();
    if (info == null) {
      return "";
    }
    return info.getMacAddress();
  }

}

Related Tutorials