i am running NanoHTTPD in my android application. i am serving some contents using this server.
I am also trying to view the contents in a web view (again in my application ).
i use the below code to get the ip address using the WifiManager as suggested here https://gist.github.com/komamitsu/1893396
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
int ipAddress = wifiManager.getConnectionInfo().getIpAddress();
final String formatedIpAddress = String.format(Locale.US, "%d.%d.%d.%d", (ipAddress & 0xff),
(ipAddress >> 8 & 0xff), (ipAddress >> 16 & 0xff), (ipAddress >> 24 & 0xff));
This code works when wifi is there but not during when phone is offline by giving the ip as 0.0.0.0 and displaying the error as ERR_PROXY_CONNECTION_FAILED.
One approach i can think is to use the localhost when network connectivity is not there. Is there any other way i can solve this problem ?
Thanks and Regards,
Saurav