Code example for WifiInfo

Methods: getIpAddress, getLinkSpeed, getMacAddress, getRssi, getSSID

0
    } 
 
    private void get_wifi() { 
        WifiInfo info = wifi.getConnectionInfo();
        int state = wifi.getWifiState();
        int strength = WifiManager.calculateSignalLevel(info.getRssi(), 5);
        boolean enabled = wifi.isWifiEnabled();
 
        name_label.setText(info.getSSID());
        enable_label.setText(enabled ?"Your wifi is enabled" :"Your wifi is not enabled");
        state_button.setText(enabled ?"Disable wifi" : "Enable wifi");
 
        switch(state) {
            case WifiManager.WIFI_STATE_ENABLED:
                data_labels[WIFISTATE].setText(" Enabled");
                break; 
            case WifiManager.WIFI_STATE_DISABLED:
                data_labels[WIFISTATE].setText(" Disabled");
                break; 
            case WifiManager.WIFI_STATE_DISABLING:
                data_labels[WIFISTATE].setText(" Being Disabled");
                break; 
            case WifiManager.WIFI_STATE_ENABLING:
                data_labels[WIFISTATE].setText(" Being Enabled");
                break; 
            case WifiManager.WIFI_STATE_UNKNOWN:
                data_labels[WIFISTATE].setText(" Unknown");
                break; 
        } 
        if(enabled) {
            data_labels[IPADD].setText(FileManager.integerToIPAddress(info.getIpAddress()));
            data_labels[MACADD].setText(info.getMacAddress());
            data_labels[SSID].setText(info.getSSID());
            data_labels[LINKSPD].setText(info.getLinkSpeed() + " Mbps");
            data_labels[SSTRENGTH].setText("strength " + strength);
        }else { 
            data_labels[IPADD].setText("N/A");
            data_labels[MACADD].setText(info.getMacAddress());
            data_labels[SSID].setText("N/A");
            data_labels[LINKSPD].setText("N/A");
            data_labels[SSTRENGTH].setText("N/A");
        } 
    }