Reputation: 41
Does this method check for an actual connection to the internet or if the device is connected to a wireless network.
I am keen to know that if the device is connected to a router for example but the router is not connected to net or is down would it return true.
My code:-
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
Upvotes: 2
Views: 2464
Reputation: 344
Your code checks whether device has any internet connection or not. If your device is connected to WI-FI or to any other network then Boolean value true is returned else false is returned.
Upvotes: 1
Reputation: 93542
Well that function doesn't check either, it returns a class that has functionality to check it. But the answer is that it would see the router and return that it has an internet connection. If you want more, have it try to access a webservice on your server (or just download something like the Google homepage).
Upvotes: 0