当前位置:  开发笔记 > 编程语言 > 正文

如何在Android 6(M)上以编程方式更改WiFi配置?

如何解决《如何在Android6(M)上以编程方式更改WiFi配置?》经验,为你挑选了0个好方法。

在这个链接中有一种方法可以在Android 5(L)中完成.有这样的方法:

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);
}

但在android M中,wifi静态ip配置中没有字段"dnsServers".这是否意味着无法在6.0中更改wifi设置?

推荐阅读
罗文彬2502852027
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有