I have an app with a form that when submitted it gets the ip address. Unfortunately the app gets the ip from the router like 192.168.1.4 or sometimes even 0.0.0.0
Here is the code i use
String hostaddr="";
public String getLocalIpAddress() {
WifiManager wifiMan = (WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInf = wifiMan.getConnectionInfo();
int ipAddress = wifiInf.getIpAddress();
String ip = String.format("%d.%d.%d.%d", (ipAddress & 0xff),(ipAddress >> 8 & 0xff), (ipAddress >> 16 & 0xff),(ipAddress >> 24 & 0xff));
return ip;
}
How can i get the right ip address?