How to check internet connection is available in ANDROID or not?

By | July 7, 2011

Today we will see how to check whether there is any internet connection available to your phone in android.If any of the internet connection is available then the below function returns true otherwise false.

private boolean checkInternetConnection() {
   ConnectivityManager conMgr = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE);
   if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() &&    conMgr.getActiveNetworkInfo().isConnected()) {
         return true;
   } else {
         System.out.println("Internet Connection Not Present");
       return false;

Dont forget to add these two permissions in the manifest file.

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>

Press the +1 button to share it across the web and leave your valuable comments also.

Leave a Reply

Your email address will not be published. Required fields are marked *