Android Check Internet Connection Tutorial

This is android check internet connection tutorial.

When we perform any network related operation like making HTTP request, then it is good to check internet or network connectivity. A device can have different types of networks like Wi-Fi or mobile network.

In android we can check internet connectivity using ConnectivityManager class. First we need to instantiate an object of ConnectivityManager class by calling getSystemService() method.

After this we can get information of all networks using getAllNetworkInfo() method. This method will return an array of NetworkInfo type.

Finally we will check connection status and show a message to user.

Below example will show you how to check internet connectivity in android

 

Android Check Internet Connection

To check network connectivity we have to add ACCESS_NETWORK_STATE permission in AndroidManifest.xml file.

AndroidManifest.xml

 

activity_main.xml

 

MainActivity.java

 

When Internet Connected

Android Check Internet Connection Tutorial

 

When Internet Not Connected

Android Check Internet Connection Tutorial

 

Comment below if you are facing any problem related to above android check internet connection tutorial.

Happy Coding!! 🙂 🙂

2 thoughts on “Android Check Internet Connection Tutorial”

  1. What if we are connected to the router but have no Internet access ? Or if we are connected to one of hotspots where we need to login first ?

Leave a Comment

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