Code example for NetworkInfo

Methods: getTypeName, isConnected

0
    private String getConnectionType(Context context) {
        try { 
            ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
 
            if ((null != activeNetwork) && activeNetwork.isConnected()) {
                return activeNetwork.getTypeName();
            } 
 
            return null; 
        } catch (Exception ignored) {
            return ""; 
        } 
    } 
 
    private void resetConnections() { 
        for (Protocol p : Jimm.getJimm().jimmModel.getProtocols()) {
            p.disconnect(false);
        } 
    }