Browse By

Check Internet Connection in Android

Check Internet Connection in Android

Check Internet Connection in Android

To Check Internet Connection in Android application is very important  for application which uses internet connectivity, If you want to use Internet for fetching data, it is always better to check Internet connection before fetching data. If Internet connection in not there and you try to fetch data from internet, it will give you an exception.

In this tutorial we will learn how to check internet connection status in android application. To check internet connectivity we will use CONNECTIVITY_SERVICE a  System service,  ConnectivityManager and NetworkInfo class.

ConnectivityManager and NetworkInfo class to Check Internet Connection in Android

	public boolean isNetworkAvailable() {
		// Get Connectivity Manager class object from Systems Service
		ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

		// Get Network Info from connectivity Manager
		NetworkInfo networkInfo = cm.getActiveNetworkInfo();

		// if no network is available networkInfo will be null
		// otherwise check if we are connected
		if (networkInfo != null && networkInfo.isConnected()) {
			return true;
		return false;


To access Internet you need to set permission <uses-permission android:name=”android.permission.INTERNET”></uses-permission> and for knowing Network Info you need to use <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”></uses-permission>. So don’t forget to put below lines in your AndroidMenifest.xml file.

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

Tip : To test wifi connectivity on the emulator you will need to press F8 to enable/disable the 3G connection.

I hope you like this article. Share your views to to improve content.

  • Ramesh HR

    Thank you