There is a way to do this in Android 5 (L) in this link. There is a way:
public static void setDNS(InetAddress dns1, InetAddress dns2, WifiConfiguration wifiConf) throws SecurityException, IllegalArgumentException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException, IllegalAccessException { Object linkProperties = null; ArrayList<InetAddress> mDnses; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { staticIpConf = wifiConf.getClass().getMethod("getStaticIpConfiguration").invoke(wifiConf); mDnses = (ArrayList<InetAddress>) getDeclaredField(staticIpConf, "dnsServers"); } else { linkProperties = getField(wifiConf, "linkProperties"); mDnses = (ArrayList<InetAddress>) getDeclaredField(linkProperties, "mDnses"); } mDnses.clear(); mDnses.add(dns1); mDnses.add(dns2); }
But in android M there is no "dnsServers" field in the ip wifi static configuration. Does this mean that there is no way to change wifi settings in 6.0?
java android android-6.0-marshmallow
xyzklm
source share