- 论坛徽章:
- 0
|
1, Connected via WIFI
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
2, Connected 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;
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/85805/showart_2122137.html |
|