Android Network State Check getMobileState(Context context)

Here you can find the source of getMobileState(Context context)

Description

get Mobile State

Declaration

public static boolean getMobileState(Context context) 

Method Source Code

//package com.java2s;

import android.content.Context;
import android.net.ConnectivityManager;

import android.net.NetworkInfo.State;

public class Main {
    public static boolean getMobileState(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        State wifistate = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
                .getState();// w  ww.ja v a  2  s  .c  om
        if (wifistate != State.CONNECTED) {
            return false;
        }

        State mobileState = cm.getNetworkInfo(
                ConnectivityManager.TYPE_MOBILE).getState();
        boolean ret = State.CONNECTED == mobileState;
        return ret;
    }
}

Related

  1. checkNetState(Context context)
  2. checkNetWorkStatus(Context context)
  3. checkNetworkState(Context context)
  4. hasConnectivity(Application application)
  5. hasConnectivity(final Context context, final int... networkTypes)
  6. hasConnectivity(final NetworkInfo info)
  7. hasInternetAvailable(Context context)