Android Context Check isOnline(Context context)

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

Description

Check if internet connection is up

Parameter

Parameter Description
context The application context

Return

True if it's up, false if it's not

Declaration

static public boolean isOnline(Context context) 

Method Source Code

//package com.java2s;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    /**//from  ww  w. j  av  a2s . com
     * Check if internet connection is up
     *
     * @param context The application context
     * @return True if it's up, false if it's not
     */
    static public boolean isOnline(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        return netInfo != null && netInfo.isConnectedOrConnecting();
    }
}

Related

  1. isMobilityInstalled(Context context)
  2. isNetAvailable(Context context)
  3. isOnline(Context c)
  4. isOnline(Context context)
  5. isOnline(Context context)
  6. isOnline(Context context)
  7. isPermissionGranted(Context ctx)
  8. isSensAppInstalled(Context context)
  9. isServiceRunning(Context ctx, String className)