ITeye博客

Get IP Address

yinter · 2010-01-14 10:43 · android · 移动开发 · Markdown

1, Connect via WIFI WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int ipAddress = wifiInfo.getIpAddress();

2, Connect via GPRS public String getLocalIpAddress() { try { for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress().toString (); } } } } catch (SocketException ex) { Log.e(S.TAG, ex.toString()); } return null; }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。