Android examples for java.net:IP Address
get IP Address via WifiManager
import android.content.Context; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; public class Main{ public static String getIPAddress(Context mContext) { WifiManager wifiManager = (WifiManager) mContext .getSystemService(Context.WIFI_SERVICE); if (!wifiManager.isWifiEnabled()) { wifiManager.setWifiEnabled(true); }/*from ww w .j ava 2 s .com*/ WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int i = wifiInfo.getIpAddress(); return (i & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + ((i >> 16) & 0xFF) + "." + ((i >> 24) & 0xFF); } }