分类: LINUX
2009-12-15 17:06:17
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
{
NetworkInterface intf = en.nextElement();
for (Enumeration
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;
}