Here you can find the source of hasInternetConnectivity(Context applicationContext)
Parameter | Description |
---|---|
applicationContext | Needs the context to get the ConnectivityManager |
public static boolean hasInternetConnectivity(Context applicationContext)
//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; } }