Reputation: 1210
I am working on android system application. I would like to know if IP address is DHCP or STATIC.
Do we have any android java class for this? Or is there any way to get it from sysfs
like /sysfs/class/net/eth0
?
Upvotes: 0
Views: 2898
Reputation: 1
If I go into Settings on my Android Samsung phone (as an example) and click on Connections, it will bring up the WiFi that it is using. Then click on the Settings (on my phone it is a Settings icon next to the WiFi name) and it will bring up more information about your connection. There you need to select "View More" and then you will see if it is set to DHCP or Static.
Upvotes: 0
Reputation: 20626
I used this to check wether is DHCP
or STATIC
years ago, perhaps you can try it out, if it does not work I'll remove the answer.
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo connectionInfo = wifiManager.getConnectionInfo();
List<WifiConfiguration> configuredNetworks = wifiManager.getConfiguredNetworks();
for (WifiConfiguration wificonf : configuredNetworks){
if (wificonf.networkId == connectionInfo.getNetworkId()){
if (wificonf.toString().toLowerCase().indexOf("DHCP".toLowerCase())>-1){
//DHCP
}else if(wificonf.toString().toLowerCase().indexOf("STATIC".toLowerCase())>-1){
//STATIC
}
break;
}
}
Upvotes: 1