How would i know whether my device is connected the web or not? How can i detect connectivity? Any sample code?
Add this permission in your AppManifest.xml file:
The method to check if network is available or not:
boolean isNetworkAvailable() {
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
return isConnected;
}
Source