小编xyz*_*klm的帖子

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

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

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);
}
Run Code Online (Sandbox Code Playgroud)

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

java android android-6.0-marshmallow

8
推荐指数
0
解决办法
770
查看次数

标签 统计

android ×1

android-6.0-marshmallow ×1

java ×1