I\'m trying to get hold of the addresses to the currently used DNS servers in my application, either I\'m connected thru Wifi or mobile. The DhcpInfo object should provide t
Calling for the getRuntime().exec
can hang your application.
android.net.NetworkUtils.runDhcp()
cause unnecessary network requests.
So I prefer to do this:
Class> SystemProperties = Class.forName("android.os.SystemProperties");
Method method = SystemProperties.getMethod("get", new Class[] { String.class });
ArrayList servers = new ArrayList();
for (String name : new String[] { "net.dns1", "net.dns2", "net.dns3", "net.dns4", }) {
String value = (String) method.invoke(null, name);
if (value != null && !"".equals(value) && !servers.contains(value))
servers.add(value);
}