Currently I working on App which supposed to work offline and online. But there in some scenario where network in available but no internet connection. Or how can I check connection speed. If connection speed is very low it should work in offline mode. Below are the code how I am checking network availability.
public static boolean isNetworkAvailable(Context ctx) {
ConnectivityManager connectivityManager = (ConnectivityManager) ctx
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager
.getActiveNetworkInfo();
if (activeNetworkInfo != null) {
if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
Log.v("Connection Type", "WI FI");
} else if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
Log.v("Connection Type", "Mobile");
}
}
return activeNetworkInfo != null
&& activeNetworkInfo.isConnectedOrConnecting();
}