am trying to check for available internet connection, i find many subjects speaking about this, but i still have a problem when i try to verify for the internet connection, the code am using is the flowing:
public boolean isOnline() {
ConnectivityManager conMgr =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() && conMgr.getActiveNetworkInfo().isConnected()) {
return true;
} else {
return false;
}
}
How can help me please ? PS: Sorry for my bad English.
Your method is correct. Also you'll need in your android manifest file:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
But keep in mind that low signal, server downtime, captive portals, content filters, other network problems can prevent your application from reaching a server. So having an active network interface doesn't guarantee that a particular networked service is available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With