B
B
Bogdan2019-04-08 19:15:29
Android
Bogdan, 2019-04-08 19:15:29

Wifi connection status?

Hello. Tell me please. I am connecting to Wifi, how to understand the status - connected to the network, or an error. If an error, then why: maybe the password is wrong?

private void connectToWifi(final String networkSSID, final String networkPassword) {
    int netID = -1;
    String confSSID = String.format("\"%s\"", networkSSID);
    String confPassword = String.format("\"%s\"", networkPassword);

    netID = getExistingNetworkID(confSSID, netID);
    
    if (netID == -1) {

        Log.d(TAG,"New wifi config added");

        WifiConfiguration conf = new WifiConfiguration();
        conf.SSID = confSSID;
        conf.preSharedKey = confPassword;
        netID = wifiManager.addNetwork(conf);

    }
    wifiManager.disconnect();
    wifiManager.enableNetwork(netID, true);
    wifiManager.reconnect();
}

Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question