Chinaunix首页 | 论坛 | 博客
  • 博客访问: 817292
  • 博文数量: 210
  • 博客积分: 10002
  • 博客等级: 上将
  • 技术积分: 1840
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-18 09:56
文章分类

全部博文(210)

文章存档

2011年(1)

2010年(6)

2009年(65)

2008年(138)

我的朋友

分类: 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 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;

}

阅读(3116) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~