Example usage for android.net NetworkInfo isAvailable

List of usage examples for android.net NetworkInfo isAvailable

Introduction

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

Prototype

@Deprecated
public boolean isAvailable() 

Source Link

Document

Indicates whether network connectivity is possible.

Usage

From source file:Main.java

public static boolean netIsEnable(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();
    if (info == null) {
        return false;
    } else {/*  w  ww  .jav a 2s . c  o m*/
        if (info.isAvailable()) {
            return true;
        } else {
            return false;
        }
    }
}

From source file:Main.java

public static boolean isWifiConnected(Context context) {
    if (context != null) {
        ConnectivityManager connManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo wifiInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (wifiInfo != null) {
            return wifiInfo.isAvailable();
        }//from   ww  w .  j  a v a  2 s  .  co m
    }
    return false;
}

From source file:Main.java

/**
 * Check for 3g internet connectivity//from w  w  w . ja  v  a2 s.co m
 *
 * @param context context
 * @return hasInternet boolean
 */
public static boolean has3gInternetAccess(@NonNull Context context) {
    try {
        boolean has3gInternet = false;
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        NetworkInfo mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (mobile != null && mobile.isAvailable() && // !ic_mobile.isRoaming() &&
                networkInfo != null && networkInfo.isConnectedOrConnecting()) {

            has3gInternet = true;
        }

        return has3gInternet;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

public static boolean isWifiAvailable(Context context) {
    ConnectivityManager mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    boolean flag = false;
    if ((mWifi != null) && ((mWifi.isAvailable()))) {
        if ((mWifi.isConnected())) {
            flag = true;//from   w  w  w .j  ava 2 s.  c  om
        }
    }
    return flag;
}

From source file:Main.java

public static boolean isMobileConnected(Context context) {
    if (context != null) {
        ConnectivityManager connManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mobileInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (mobileInfo != null) {
            return mobileInfo.isAvailable();
        }//  w  w  w  .  j  a va2s.  c o m
    }
    return false;
}

From source file:Main.java

public static boolean isNetWorkConnected(Context context) {
    if (context != null) {
        ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
        if (mNetworkInfo != null) {
            return mNetworkInfo.isAvailable();
        }//from ww  w.ja  va  2 s.co  m
    }

    return false;
}

From source file:Main.java

public static boolean isNetWorkConnected(Context context) {
    if (context != null) {
        ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
        if (mNetworkInfo != null) {
            return mNetworkInfo.isAvailable() && mNetworkInfo.isConnected();
        }/*from  w w  w .  j  ava 2s.  c o m*/
    }

    return false;
}

From source file:Main.java

public static boolean isWapNet(Context context) {
    ConnectivityManager conManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = conManager.getActiveNetworkInfo();
    if (info != null && info.isAvailable()) {
        if (info.getType() == 1) {
            return false;
        } else {// w  w  w . j ava 2  s.c o m
            String currentAPN = info.getExtraInfo();
            return !TextUtils.isEmpty(currentAPN) && (currentAPN.equals("cmwap") || currentAPN.equals("uniwap")
                    || currentAPN.equals("3gwap"));
        }
    } else {
        return false;
    }
}

From source file:Main.java

public static boolean isNetworkAvail(Context context) {
    if (context != null) {
        ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
        if (mNetworkInfo != null) {
            return mNetworkInfo.isAvailable();
        }//from  w ww . j  a  v a 2 s  . co m
    }
    return false;
}

From source file:Main.java

/**
 * This method is used to check whether GPRS is connected or not.
 * @param appContext//from  ww w .  j av  a  2 s  .c o m
 * @return
 */
public static boolean isGPRSConnected(Context appContext) {
    boolean isConnected = false;
    if (isMobileDataEnables(appContext)) {
        ConnectivityManager connMgr = (ConnectivityManager) appContext
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

        if (mobile != null && mobile.isAvailable() && mobile.isConnected()) {

            isConnected = true;
        }
        return isConnected;
    } else {
        return isConnected;
    }
}