get Ip from WifiManager - Android Wifi

Android examples for Wifi:Wifi Connection

Description

get Ip from WifiManager

Demo Code


//package com.java2s;
import android.content.Context;

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

import android.text.format.Formatter;

public class Main {
    public static String getIp(Context context) {
        WifiManager wifiMgr = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
        int ip = wifiInfo.getIpAddress();
        String ipAddress = Formatter.formatIpAddress(ip);
        return ipAddress;
    }//from   w w w.  j  a v  a  2s . c  om
}

Related Tutorials