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

booleancheckNetState(Context context)
check Net State
boolean netstate = false;
ConnectivityManager connectivity = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
    NetworkInfo[] info = connectivity.getAllNetworkInfo();
    if (info != null) {
        for (int i = 0; i < info.length; i++) {
            if (info[i].getState() == NetworkInfo.State.CONNECTED) {
...
intcheckNetWorkStatus(Context context)
check Net Work Status
int status = 0;
ConnectivityManager connMgr = (ConnectivityManager) context
        .getApplicationContext().getSystemService(
                Context.CONNECTIVITY_SERVICE);
android.net.NetworkInfo wifi = connMgr
        .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
android.net.NetworkInfo mobile = connMgr
        .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
...
booleancheckNetworkState(Context context)
check Network State
boolean netstate = false;
ConnectivityManager connectivity = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
    NetworkInfo[] info = connectivity.getAllNetworkInfo();
    if (info != null) {
        for (int i = 0; i < info.length; i++) {
            if (info[i].getState() == NetworkInfo.State.CONNECTED) {
...
booleangetMobileState(Context context)
get Mobile State
ConnectivityManager cm = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
State wifistate = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
        .getState();
if (wifistate != State.CONNECTED) {
    return false;
State mobileState = cm.getNetworkInfo(
...
booleanhasConnectivity(Application application)
has Connectivity
ConnectivityManager cm = (ConnectivityManager) application
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifiNetwork = cm
        .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (wifiNetwork != null && wifiNetwork.isConnected()) {
    return true;
NetworkInfo mobileNetwork = cm
...
booleanhasConnectivity(final Context context, final int... networkTypes)
has Connectivity
final ConnectivityManager connectivity = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
if (networkTypes.length > 0)
    for (final int networkType : networkTypes)
        if (ConnectivityManager.isNetworkTypeValid(networkType))
            return hasConnectivity(connectivity
                    .getNetworkInfo(networkType));
return hasConnectivity(connectivity.getActiveNetworkInfo());
...
booleanhasConnectivity(final NetworkInfo info)
has Connectivity
return null != info && info.isAvailable() && info.isConnected();
booleanhasInternetAvailable(Context context)
has Internet Available
ConnectivityManager cm = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {
    return true;
return false;
booleanhasMobileConnectivity(Context context)
has Mobile Connectivity
ConnectivityManager cm = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mobileInfo = cm
        .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (mobileInfo != null) {
    return true;
} else {
    return false;
...
booleanhasNoConnectivity(Application application)
has No Connectivity
return !hasConnectivity(application);