Example usage for android.net ConnectivityManager toString

List of usage examples for android.net ConnectivityManager toString

Introduction

In this page you can find the example usage for android.net ConnectivityManager toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.brandroid.openmanager.fragments.DialogHandler.java

public static String getNetworkInfo(Context c) {
    String ret = getNetworkInterfaces();

    ConnectivityManager conman = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (conman == null)
        ret += "No Connectivity?\n";
    else {//  ww  w  .  j  a  v  a  2 s.c  o m
        ret += "Connectivity Info:\n" + conman.toString() + "\n";
        for (NetworkInfo ni : conman.getAllNetworkInfo()) {
            if (!ni.isAvailable())
                continue;
            ret += "Network [" + ni.getTypeName() + "]: " + getNetworkInfoInfo(ni) + "\n";
        }
    }
    try {
        WifiManager wifi = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
        if (wifi == null)
            ret += "No wifi\n";
        else {
            ret += "Wifi Info:\n" + wifi.toString() + "\n";
            ret += "Status: " + (wifi.isWifiEnabled() ? "ENABLED" : "DISABLED") + "\n";
            ret += "ip=" + getReadableIP(wifi.getConnectionInfo().getIpAddress()) + "/ " + "mac="
                    + wifi.getConnectionInfo().getMacAddress() + "/ " + "b="
                    + wifi.getConnectionInfo().getBSSID() + "/ " + "s=" + wifi.getConnectionInfo().getSSID();
            DhcpInfo dh = wifi.getDhcpInfo();
            if (dh == null)
                ret += "No DHCP\n";
            else {
                ret += "IP: " + getReadableIP(dh.ipAddress) + "\n";
                ret += "Gateway: " + getReadableIP(dh.gateway) + "\n";
                ret += "DNS: " + getReadableIP(dh.dns1) + " " + getReadableIP(dh.dns2) + "\n";
            }
        }
    } catch (SecurityException sec) {
        ret += "No Wifi permissions.\n";
    }
    return ret;
}