I have a problem with checking internet connection in android at runtime. I use some different methods to check internet connection but i don\'t know which one is better . b
public static boolean isNetworkAvailable(Context context) {
try {
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService
(Context.CONNECTIVITY_SERVICE);
if (connManager.getActiveNetworkInfo() != null && connManager.getActiveNetworkInfo()
.isAvailable() && connManager.getActiveNetworkInfo().isConnected()) {
return true;
}
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
return false;
}
then just call this function from your fragment
or Activity
will work