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 context)
is Network Available
ConnectivityManager connectivity = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
    Log.i("NetWorkState", "Unavailabel");
    return false;
} else {
    NetworkInfo[] info = connectivity.getAllNetworkInfo();
    if (info != null) {
...
booleanisNetworkConnected(Context context)
is Network Connected
if (context != null) {
    ConnectivityManager cm = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null
            && activeNetwork.isConnectedOrConnecting();
} else {
    return false;
...
booleanonNetwork(Context context)
on Network
final ConnectivityManager conMgr = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
if (activeNetwork != null && activeNetwork.isConnected()) {
    return true;
} else {
    return false;
booleanhaveNetworkConnection(Context context)
have Network Connection
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
    if (ni.getTypeName().equalsIgnoreCase("WIFI"))
        if (ni.isConnected())
...
booleanisNetworkConnected(Context context)
Check if network exists and determine if it has Internet connectivity
ConnectivityManager cm = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
return (ni != null && ni.isConnected());
booleanisNetworkEnabled(Context context)
is Network Enabled
ConnectivityManager conn = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = conn.getActiveNetworkInfo();
return (info != null && info.isConnected());
booleancheck3GNetwork(Context context)
check G Network
ConnectivityManager connectivity = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
    return false;
} else {
    NetworkInfo info = connectivity.getActiveNetworkInfo();
    if (info == null) {
        return false;
...
BooleanIsNetworkConnected(Context context)
Is Network Connected
ConnectivityManager manager = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] networks = manager.getAllNetworkInfo();
for (NetworkInfo network : networks) {
    if (network.getTypeName().equalsIgnoreCase("WIFI")) {
        if (network.isConnected() && network.isAvailable()
                && network.isConnectedOrConnecting()) {
            return true;
...
booleanisNetworkAvailableExt(Context paramContext)
Check mobile network and wireless status
ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext
        .getSystemService("connectivity");
if (localConnectivityManager == null) {
    return false;
while (true) {
    NetworkInfo localNetworkInfo = localConnectivityManager
            .getActiveNetworkInfo();
...
booleanisNetworkAvailable(Context context)
Checks device for network connectivity
boolean state = false;
if (context != null) {
    ConnectivityManager cm = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnected()) {
        Log.i(TAG, "The device currently has data connectivity");
        state = true;
...