Android-禁用wifiManager.disconnect用户弹出窗口

问题描述

我尝试使用Wifimanger直接与AP连接,但是我不知道如何在每次调用wifiManager.disconnect()时禁用用户弹出窗口。

public void Connect_To_AP(String SSID,String pass)
    {
        String networkSSID = SSID;
        String networkPass = pass;

        peripheralTextView.append("Connecting to AP: " + SSID + "\n");

        //1.- Create a Wifi Configuration
        WifiConfiguration wconf = new WifiConfiguration();
        wconf.SSID = "\"" + networkSSID + "\"";   // Please note the quotes. String should contain ssid in quotes

        //2.- Configure Network Security Type
        // FOR WEP
        //conf.wepKeys[0] = "\"" + networkPass + "\"";
        //conf.wepTxKeyIndex = 0;
        //conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
        //conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);

        // FOR WPA
        wconf.preSharedKey = "\""+ networkPass +"\"";

        // FOR OPEN
        //conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

        // 3.- Add Configuration to a Wifi_Manager
        WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
        wifiManager.addNetwork(wconf);

        //4.- Enable and Connect.        
        List<WifiConfiguration> list = wifiManager.getConfigurednetworks();
        for( WifiConfiguration i : list )
        {
            if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\""))
            {
                wifiManager.disconnect();
                wifiManager.enableNetwork(i.networkId,true);
                wifiManager.reconnect();
                break;
            }
        }
    }

如何禁用更改wifi AP用户的PorUp?

解决方法

...我发现了问题。 是电话权限问题,而不是源于代码。 第一次在Android Studio调试器中执行该应用程序时,我选择“询问”权限。 现在。我将“更改wifi连接性”权限更改为“始终”,现在可以正常运行,都没有显示弹出权限。