In my app I am checking internet connection with below method :
public static boolean isOnline(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
Now, in activity I am checking for internet connection as below :
if (Constant.isOnline(mContext))
loadNotificationList();
else
Constant.displayToast(mContext, getResources().getString(R.string.msg_internet));
Now, If MobileData or wi-fi is off I am getting toast message. It's fine. But, the issue is in below scenario :
==> I am using wi-fi of another device in which hotspot is on and my device got connected to it. now, I have turned off the mobile data of that another device. that means: no internet access for me. But, still i am getting true from the method : isOnline()
so, I think the method is checking for the state only. What if I wanna go check that internet access is available in real or not?
Thanks.