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 paramContext)
is Network Available
ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext
        .getSystemService(Activity.CONNECTIVITY_SERVICE);
final NetworkInfo localNetworkInfo1 = localConnectivityManager
        .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
final NetworkInfo localNetworkInfo2 = localConnectivityManager
        .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
return (localNetworkInfo1.isConnected() && localNetworkInfo2
        .isConnected());
...
booleanisNetworkAvailable(Context context)
is Network Available
ConnectivityManager connectivity = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
    Log.w(LOG_TAG, "couldn't get connectivity manager");
} else {
    NetworkInfo[] info = connectivity.getAllNetworkInfo();
    if (info != null) {
        for (int i = 0; i < info.length; i++) {
...
booleanisNetworkRoaming(Context context)
is Network Roaming
ConnectivityManager connectivity = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
    Log.w(LOG_TAG, "couldn't get connectivity manager");
} else {
    NetworkInfo info = connectivity.getActiveNetworkInfo();
    if (info != null
            && info.getType() == ConnectivityManager.TYPE_MOBILE) {
...
booleanisMobileDataEnable(Context context)
is Mobile Data Enable
ConnectivityManager connectivityManager = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isMobileDataEnable = false;
isMobileDataEnable = connectivityManager.getNetworkInfo(
        ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
return isMobileDataEnable;
booleanisWifiDataEnable(Context context)
is Wifi Data Enable
ConnectivityManager connectivityManager = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isWifiDataEnable = false;
isWifiDataEnable = connectivityManager.getNetworkInfo(
        ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
return isWifiDataEnable;
booleanisMobileConnected(Context context)
is Mobile Connected
if (context != null) {
    ConnectivityManager mConnectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mMobileNetworkInfo = mConnectivityManager
            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (mMobileNetworkInfo != null) {
        return mMobileNetworkInfo.isAvailable()
                && mMobileNetworkInfo.isConnected();
...
booleanisNetworkAvailable(Context context)
is Network Available
ConnectivityManager mgr = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] info = mgr.getAllNetworkInfo();
if (info != null) {
    for (int i = 0; i < info.length; i++) {
        if (info[i].getState() == NetworkInfo.State.CONNECTED) {
            return true;
return false;
booleanisNetworkConnected(Context context)
is Network Connected
if (context != null) {
    ConnectivityManager mConnectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mNetworkInfo = mConnectivityManager
            .getActiveNetworkInfo();
    if (mNetworkInfo != null) {
        return mNetworkInfo.isAvailable()
                && mNetworkInfo.isConnected();
...
booleanisMobileConnected(Context context)
is Mobile Connected
if (context != null) {
    ConnectivityManager mConnectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mMobileNetworkInfo = mConnectivityManager
            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (mMobileNetworkInfo != null) {
        return mMobileNetworkInfo.isAvailable();
return false;
booleanisNetworkConnected(Context context)
is Network Connected
if (context != null) {
    ConnectivityManager mConnectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mNetworkInfo = mConnectivityManager
            .getActiveNetworkInfo();
    if (mNetworkInfo != null) {
        return mNetworkInfo.isAvailable();
return false;