Android Utililty Methods Network State Check

List of utility methods to do Network State Check

Description

The list of methods to do Network State Check are organized into topic(s).

Method

booleanisNetworkAvailable(Context context)
is Network Available
ConnectivityManager conMgr = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
boolean availability = false;
try {
    if (conMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
            .getState() == NetworkInfo.State.CONNECTED
            || conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
                    .getState() == NetworkInfo.State.CONNECTED) {
...
booleanisNetworkAvailable(Context context)
is Network Available
ConnectivityManager connectivityManager = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager
        .getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
booleanisMobileOnline(Context context)
is Mobile Online
ConnectivityManager conMan = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
State mobile = conMan.getNetworkInfo(
        ConnectivityManager.TYPE_MOBILE).getState();
if (mobile == NetworkInfo.State.CONNECTED)
    return true;
else
    return false;
...
BooleanisInternetReachable(Context context)
is Internet Reachable
SharedPreferences preferences = PreferenceManager
        .getDefaultSharedPreferences(context);
Boolean ret;
ConnectivityManager connectivityManager = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifiNetworkInfo = connectivityManager
        .getNetworkInfo(ConnectivityManager.TYPE_WIFI), dataNetworkInfo = connectivityManager
        .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
...
booleanisHightBandwidthConnection(Context context)
is Hight Bandwidth Connection
ConnectivityManager cm = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
return (info != null && info.isConnected() && isConnectionFast(
        info.getType(), info.getSubtype()));
booleanisConnectionFast(int type, int subType)
is Connection Fast
if (type == ConnectivityManager.TYPE_WIFI) {
    return true;
} else if (type == ConnectivityManager.TYPE_MOBILE) {
    switch (subType) {
    case TelephonyManager.NETWORK_TYPE_1xRTT:
        return false; 
    case TelephonyManager.NETWORK_TYPE_CDMA:
        return false; 
...
BooleanisNetAvailable(Context context)
Checks if Network connectivity is available to download OpenCellID data
try {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiInfo = connectivityManager
            .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo mobileInfo = connectivityManager
            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (wifiInfo != null && mobileInfo != null) {
...
booleanisNetworkAvailable(Context context)
is Network Available
try {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager
            .getActiveNetworkInfo();
    return activeNetworkInfo != null;
} catch (Exception e) {
return false;
booleanisNetworkAvailable(Context context)
is Network Available
boolean netWorkStatus = false;
if (null != context) {
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connManager.getActiveNetworkInfo() != null) {
        netWorkStatus = connManager.getActiveNetworkInfo()
                .isAvailable();
return netWorkStatus;
booleanisNetworkAvailable(Context context)
is Network Available
try {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo info = connectivity.getActiveNetworkInfo();
        if (info != null && info.isConnected()) {
            if (info.getState() == NetworkInfo.State.CONNECTED) {
                return true;
...