I want to execute my application offline also, so I need to check if currently an internet connection is available or not. Can anybody tell me how to check if internet is av
Use the method checkConnectivity:
if (checkConnectivity()){
//do something
}
Method to check your connectivity:
private boolean checkConnectivity() {
boolean enabled = true;
ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectivityManager.getActiveNetworkInfo();
if ((info == null || !info.isConnected() || !info.isAvailable())) {
Toast.makeText(getApplicationContext(), "Sin conexión a Internet...", Toast.LENGTH_SHORT).show();
return false;
} else {
return true;
}
return false;
}