is Mobile Network Available - Android Network

Android examples for Network:Network Status

Description

is Mobile Network Available

Demo Code


//package com.java2s;

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

public class Main {
    public static boolean isMobileNetworkAvailable(Context context) {
        ConnectivityManager manager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo wifiInfo = manager//from   www . j a  va  2  s .c  o  m
                .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        NetworkInfo mobileInfo = manager
                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        return (wifiInfo == null ? false : wifiInfo.isConnected())
                || (mobileInfo == null ? false : mobileInfo.isConnected());
    }
}

Related Tutorials