Code example for WifiManager

Methods: getConnectionInfogetDhcpInfogetWifiStatepingSupplicant

1
        send(getStatus()); 
    } 
     
    private static XmppMsg getStatus() { 
        XmppMsg res = new XmppMsg();
    	int status = sWifiManager.getWifiState();
    	String statusStr;
    	switch (status) {
    	case WifiManager.WIFI_STATE_DISABLED:
    		statusStr = "disabled";
    		break; 
    	case WifiManager.WIFI_STATE_DISABLING:
    		statusStr = "disabling";
    		break; 
    	case WifiManager.WIFI_STATE_ENABLED:
    		statusStr = "enabled";
    		break; 
    	case WifiManager.WIFI_STATE_ENABLING:
    		statusStr = "enabling";
    		break; 
    	default: 
    		statusStr = "unkown";
    		break; 
    	}    	 
    	res.append("Wifi state is ");
    	res.appendBold(statusStr);
    	res.newLine();
    	 
        boolean supplicant_alive = sWifiManager.pingSupplicant();
        String supplicant_status;
        if (supplicant_alive) {
            supplicant_status = "WPA Supplicant is responding";
        } else { 
            supplicant_status = "WPA Supplicant is NOT responding";
        } 
    	res.appendLine(supplicant_status);
    	 
    	WifiInfo info = sWifiManager.getConnectionInfo();
    	if (info != null) {
    	    res.newLine();
    	    String bssid = info.getBSSID();
    	    String ip = Tools.ipIntToString(info.getIpAddress());
    	    String ssid = info.getSSID();
    	    int rssi = info.getRssi();
    	     
    	    // bssid 
    	    res.appendBold("BSSID: ");
    	    res.appendLine(bssid);
    	    // ssid 
    	    res.appendBold("SSID: ");
    	    res.appendLine(ssid);
    	    // ip 
    	    res.appendBold("IP: ");
    	    res.appendLine(ip);
    	    // link speed 
    	    res.appendBold("Current link speed: ");
    	    res.append(info.getLinkSpeed());
    	    res.appendLine(WifiInfo.LINK_SPEED_UNITS);
    	    // rssi 
    	    res.appendBold("Received signal strength indicator: ");
    	    res.appendLine(rssi);
    	    // rssi - level 
    	    res.appendBold("RSSI on a scale from 1 to " + RSSI_LEVEL + ": ");
    	    res.appendLine(Integer.toString(WifiManager.calculateSignalLevel(rssi, RSSI_LEVEL)));
    	} 
    	 
    	DhcpInfo dhcpInfo = sWifiManager.getDhcpInfo();
    	if (dhcpInfo != null) {    	  
    	    res.newLine();
    	    res.appendBoldLine("DHCP Info");
    	    res.appendBold("DNS1: ");
    	    res.appendLine(Tools.ipIntToString(dhcpInfo.dns1));