Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

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

public class Main {
    public static final String DEFAULT_WIFI_ADDRESS = "00-00-00-00-00-00";

    public static String getWifiAddress(Context pContext) {
        String address = DEFAULT_WIFI_ADDRESS;
        if (pContext != null) {
            WifiInfo localWifiInfo = ((WifiManager) pContext.getSystemService("wifi")).getConnectionInfo();
            if (localWifiInfo != null) {
                address = localWifiInfo.getMacAddress();
                if (address == null || address.trim().equals(""))
                    address = DEFAULT_WIFI_ADDRESS;
                return address;
            }

        }
        return DEFAULT_WIFI_ADDRESS;
    }
}