Change WiFi configuration using Android java code

Activity Forums Android mobile app Change WiFi configuration using Android java code

  • This topic is empty.
  • Creator
    Topic
  • #119
    adcocitclass
    Keymaster

    Android java code to change WiFi configuration


    public static void setDNS(InetAddress dns1, InetAddress dns2, WifiConfiguration wifiConf)
    throws SecurityException, IllegalArgumentException, NoSuchMethodException, InvocationTargetException,
    NoSuchFieldException, IllegalAccessException {

    Object linkProperties = null;
    ArrayList mDnses;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    staticIpConf = wifiConf.getClass().getMethod("getStaticIpConfiguration").invoke(wifiConf);
    mDnses = (ArrayList) getDeclaredField(staticIpConf, "dnsServers");
    }
    else {
    linkProperties = getField(wifiConf, "linkProperties");
    mDnses = (ArrayList
    ) getDeclaredField(linkProperties, "mDnses");
    }

    mDnses.clear();
    mDnses.add(dns1);
    mDnses.add(dns2);
    }

  • You must be logged in to reply to this topic.