Example usage for android.net NetworkInfo getType

List of usage examples for android.net NetworkInfo getType

Introduction

In this page you can find the example usage for android.net NetworkInfo getType.

Prototype

@Deprecated
public int getType() 

Source Link

Document

Reports the type of network to which the info in this NetworkInfo pertains.

Usage

From source file:Main.java

public static boolean isMobileConnected(Context context) {
    if (context != null) {
        ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
        if (mNetworkInfo != null) {
            if (mNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                return true;
            }//from  ww  w  .  j  av a2 s  .  c om
        }
    }
    return false;
}

From source file:Main.java

public static boolean isWifiConnected(Context context) {
    if (context != null) {
        ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
        if (mNetworkInfo != null) {
            if (mNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                return true;
            }//  www  .ja  v  a 2s .co  m
        }
    }
    return false;
}

From source file:Main.java

/**
 * get mobile NetWork Type/*from ww w. j  a va2 s.  c  om*/
 * 
 * @param context
 * @return
 */
public static String getNetWorkType(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo workinfo = connectivityManager.getActiveNetworkInfo();
    if (workinfo != null) {
        if (workinfo.getType() == ConnectivityManager.TYPE_BLUETOOTH) {
            return "b";
        }
        if (workinfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            return "m";
        }
        if (workinfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return "w";
        }
    }
    return null;
}

From source file:Main.java

public static int getActiveNetworkType(Context context) {
    int defaultValue = -1;
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm == null) {
        return defaultValue;
    }//from  w w w . j  av a2s.c o m
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info == null) {
        return defaultValue;
    }
    return info.getType();
}

From source file:Main.java

public static int getNetWorkType(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager == null ? null : connectivityManager.getActiveNetworkInfo();
    return networkInfo == null ? -1 : networkInfo.getType();
}

From source file:Main.java

public static boolean isHighBandwidthConnection(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    return (info != null && info.isConnected() && isConnectionFast(info.getType(), info.getSubtype()));
}

From source file:Main.java

/**
 * checks if there is WI-FI connection available
 * @param currentActivity//from  w  w  w.  j ava  2 s  . c o  m
 * @return
 */
public static boolean isWifiInternetAvailable(Context currentActivity) {
    final ConnectivityManager connectivityManager = (ConnectivityManager) currentActivity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo != null) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            if (networkInfo.isConnected()) {
                return true;
            }
        }
    }

    return false;
}

From source file:Main.java

/**
 * checks if there is network connection available
 * @param currentActivity/*from  w  w  w .  j  a  v  a2 s . co  m*/
 * @return
 */
public static boolean isMobileInternetAvailable(Activity currentActivity) {
    final ConnectivityManager connectivityManager = (ConnectivityManager) currentActivity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo != null) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            if (networkInfo.isConnected()) {
                return true;
            }
        }
    }

    return false;
}

From source file:Main.java

@SuppressLint("DefaultLocale")
public static String getAPNTypeString(Context context) {
    String netType = "";
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

    if (networkInfo != null) {
        int nType = networkInfo.getType();
        if (nType == ConnectivityManager.TYPE_MOBILE) {
            String eInfo = networkInfo.getExtraInfo();
            if (eInfo != null) {
                netType = eInfo.toLowerCase();

            }/*from   ww w .j  av  a  2  s  .  c o m*/
        } else if (nType == ConnectivityManager.TYPE_WIFI) {
            netType = "wifi";
        }
    }

    return netType;
}

From source file:Main.java

/**
 * checks if there is WI-FI or network connection available
 * @param currentActivity//from w ww  .jav a 2 s . c om
 * @return
 */
public static boolean isInternetAvailable(Context currentActivity) {
    final ConnectivityManager conectivityManager = (ConnectivityManager) currentActivity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = conectivityManager.getActiveNetworkInfo();
    if (networkInfo != null) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            if (networkInfo.isConnected()) {
                return true;
            }
        } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            if (networkInfo.isConnected()) {
                return true;
            }
        }
    }

    return false;
}