How to get the real IP address ? I use Code below, the result always be 127.0.0.1
if (getIpType(context) == IP_TYPE_WIFI) {
WifiManager wifi_service = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
DhcpInfo dhcpInfo = wifi_service.getDhcpInfo();
WifiInfo wifiinfo = wifi_service.getConnectionInfo();
String ip = Formatter.formatIpAddress(dhcpInfo.ipAddress);
} else {
Runnable IpRunnable = new Runnable() {
@Override
public void run() {
InetAddress addr;
String localIp = null;
try {
addr = InetAddress.getLocalHost();
localIp = addr.getHostAddress();
} catch (UnknownHostException e) {
}
}
};
Thread payThread = new Thread(IpRunnable);
payThread.start();
}