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 String getWifiIpAddress(Context pContext) {
        WifiInfo localWifiInfo = null;
        if (pContext != null) {
            localWifiInfo = ((WifiManager) pContext.getSystemService("wifi")).getConnectionInfo();
            if (localWifiInfo != null) {
                String str = convertIntToIp(localWifiInfo.getIpAddress());
                return str;
            }
        }
        return "";
    }

    private static String convertIntToIp(int paramInt) {
        return (paramInt & 0xFF) + "." + (0xFF & paramInt >> 8) + "." + (0xFF & paramInt >> 16) + "."
                + (0xFF & paramInt >> 24);
    }
}