如果编程启用,Android 7.0上的热点将不允许设备进行连接

时间:2018-11-08 11:48:37

标签: java android hotspot

我正面临一个非常奇怪的行为。我正在使用以下功能以编程方式打开wifi热点

    public static boolean onTethering(Context context) {
    WifiManager wifimanager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    WifiConfiguration wificonfiguration = null;
    try {
        // if WiFi is on, turn it off
        if(isApOn(context)) {
            if (wifimanager != null) {
                wifimanager.setWifiEnabled(false);
            }
        }
        Method method = wifimanager != null ? wifimanager.getClass().getMethod("startTethering", WifiConfiguration.class, boolean.class) : null;

       // Method method = wifimanager.getClass().getDeclaredMethod("startTethering",int.class,boolean.class,callbackClass,Handler.class);

        if (method != null) {
            method.invoke(wifimanager, null, !isApOn(context));
        }else{
            return false;
        }
        return true;
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

该功能在Android Lollipop和棉花糖中都运行良好。但是,当我在Android 7.0中安装我的应用程序时,它表现出非常奇怪的行为。热点已打开并且似乎可以正常工作,但是当我尝试将设备连接到热点时,它始终停留在获取IP地址循环中。连接其他Android设备需要花费很长时间,有时甚至会完全失败。

我正在尝试将NodeMCU连接到此热点。

注意:如果我从设置设备中手动打开“热点”,则会立即连接到该设备。

有什么我想念的吗?

0 个答案:

没有答案