get Wifi Mac address - Android Wifi

Android examples for Wifi:Wifi Address

Description

get Wifi Mac address

Demo Code


//package com.java2s;

import android.content.Context;

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

import android.util.Log;

public class Main {
    private static final String TAG = "LauncherUtils";

    public static String getWifiMac(Context context) {
        String wifiMac = null;//ww  w  .j a va 2  s . c  om
        // TODO
        WifiManager wifiMgr = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        if (wifiMgr == null) {
            Log.e(TAG, "[getWifiMac] can not get WIfiManager!");
            return null;
        }

        WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
        if (wifiInfo == null) {
            Log.e(TAG, "[getWifiMac] can not get WifiInfo!");
            return null;
        }

        wifiMac = wifiInfo.getMacAddress();
        Log.d(TAG, "[getWifiMac] wifi mac : " + wifiMac);
        return wifiMac;
    }
}

Related Tutorials