2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

How to check if internet connection is there to load a page in WebView

I want to check if internet connection is there before loading the WebView or load the page from URL. How to check?

userimage

Try below code to check if internet connection is there or not:

public boolean checkIfInternetConnectionThere(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager.getActiveNetworkInfo() != null
            && connectivityManager.getActiveNetworkInfo().isAvailable()
            && connectivityManager.getActiveNetworkInfo().isConnected()) {
        return true;
    } else {
        return false;
    }
}
Answer is