How to get DhcpInfo() (gateway ip, netmask, dns, etc) of android device connected via Ethernet?
I know how to get it if device connected via Wifi and using ACCESS_WIFI_STATE permission:
WifiManager wifi = (WifiManager) context.getSystemService(Service.WIFI_SERVICE);
DhcpInfo dhcp = wifi.getDhcpInfo();
But I still not found the way to get it if device connected via ethernet... Thanks
In your AndroidManifest.xml file
Your code:
Output
You can't reach to know whether you are connected via wifi or network using
WifiManager
asWifiManager
only deals with wifi. You have to useConnectivityManager
. I updated the code again where I mergedWifiManager
andConnectivityManager
to produce the result that you wanted.