Look at the code
public String getIp () {
Log.v ("NetUtilID", "getIP");
Log.v ("ID", "get myip");
String ip = "";
/ / Get wifi service
WifiManager wifiManager = (WifiManager) context
. GetSystemService (Context.WIFI_SERVICE);
/ / Determine whether to open
wifiif (! wifiManager.isWifiEnabled ()) {
ip = getGprsIp ();
} Else {
WifiInfo wifiInfo = wifiManager.getConnectionInfo ();
int ipAddress = wifiInfo.getIpAddress ();
ip = intToIp (ipAddress);
}
return ip;
}
private String getGprsIp () {
try {
for (Enumerationen = NetworkInterface
. GetNetworkInterfaces (); en.hasMoreElements () ;) {
NetworkInterface intf = en.nextElement ();
for (EnumerationenumIpAddr = 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 "wocao";
}
private String intToIp (int i) {
return (i & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + ((i >> 16) & 0xFF)
"." + + (I >> 24 & 0xFF);
}
When using wlan network, obtain ip normal, but the use of data traffic, ip is fe80 :: 2c7c: 136f: 2d8c: 4647% rmnet0 this stuff, what ah, seeking Great God help Kazakhstan busy
Reply:
how no one answered ah oilReply:
Do not csdn oil greatly God, becameReply:
That is the ipv6 address
Reply:
Finally someone answered, very excited, ah, with weak ask, to get the normal ipv4 address how to do ah, android phones can connect wifi and data traffic, wifi's ip I would, that is, data traffic (ie mobile 3g) do not know how to get, learn online code is fe80 :: 2c7c: 136f: 2d8c: 4647% rmnet0, ball big God
No comments:
Post a Comment