想知道android手机数据流量下IP地址

用*#*#4636#*#*看IP时却显示:ip addr not reachable,怎么才能知道连着数据流量时自己手机的IP地址,手机是android的

使用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("WifiPreference IpAddress", ex.toString());

}

return null;

}

百度搜索ip,是这样吗?