How to programmatically change WiFi configuration on Android 6 (M)?

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?

+7
java android android-6.0-marshmallow
source share

No one has answered this question yet.

See similar questions:

5
Changing WiFi configuration on Android 5 (L) programmatically

or similar:

3799
How do I read / convert an InputStream to a string in Java?
3606
Close / hide Android soft keyboard
3324
How to generate random integers in a specific range in Java?
3295
Why is the Android emulator so slow? How can we speed up Android emulator development?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to keep Android activity state by saving instance state?
2284
How can I fix the 'android.os.NetworkOnMainThreadException'?
2097
Is there a way to run Python on Android?
1844
What is "Context" on Android?

All Articles