Return the MAC address of the WLAN interface mac Address the MAC address in XX:XX:XX:XX:XX:XX - Android Network

Android examples for Network:Mac Address

Description

Return the MAC address of the WLAN interface mac Address the MAC address in XX:XX:XX:XX:XX:XX

Demo Code


//package com.java2s;

import android.content.Context;

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

public class Main {
    /**//  w  w w  .  j ava  2s.c  om
     * Return the MAC address of the WLAN interface macAddress <br>
     * the MAC address in {@code XX:XX:XX:XX:XX:XX}
     * @return
     */
    public static final String obtainDeviceMac(Context context) {
        String macAddress = null;
        WifiManager wm = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = (null == wm ? null : wm.getConnectionInfo());
        if (null != info) {
            macAddress = info.getMacAddress();
        }
        if (macAddress == null) {
            macAddress = "";
        }
        return macAddress;
    }
}

Related Tutorials