Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2021741
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类: Java

2009-03-19 17:54:15

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;
}

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