Android Context Check hasInternetConnectivity(Context applicationContext)

Here you can find the source of hasInternetConnectivity(Context applicationContext)

Description

Checks if there is an usable Internet connection

License

Apache License

Parameter

Parameter Description
applicationContext Needs the context to get the ConnectivityManager

Return

true if there is an active Internet connection. false otherwise

Declaration

public static boolean hasInternetConnectivity(Context applicationContext) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import android.content.Context;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    /**/*from  w w w.  j  av  a  2s  .co m*/
     * Checks if there is an usable Internet connection
     * 
     * @param applicationContext
     *       Needs the context to get the ConnectivityManager
     * @return
     *       true if there is an active Internet connection.
     *       false otherwise 
     */
    public static boolean hasInternetConnectivity(Context applicationContext) {
        ConnectivityManager connManager = (ConnectivityManager) applicationContext
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = connManager.getActiveNetworkInfo();
        if (info != null)
            return info.isConnected();
        else
            return false;
    }
}

Related

  1. hasAsymmericMasterSecret(Context context)
  2. hasConnection(Context c)
  3. hasInternetConnection(Context context)
  4. hasNotificationPermission(Context context)
  5. hasOtherSPAppsInstalled(Context context)
  6. hasTelephony(@Nonnull Context context)
  7. hasVibrationPermission(Context context)