Check Internet connectivity in android
Many applications connect to Internet to perform certain tasks, so in this tutorial we will see how to create a java class to check the internet connection of mobile. So lets begin. Step 1- we nee d to provide permission in manifest file. < manifest > < uses-permission android :name= "android.permission.INTERNET" /> < uses-permission android :name= "android.permission.ACCESS_NETWORK_STATE" /> < application... ............... </ activity > </ manifest > Step 2- create below function after onCreate() method to check Internet connection. protected boolean isOnline() { ConnectivityManager cm = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) ...