Reputation: 994
in a Service I'm using the following function for verifying internet connection:
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
return !(networkInfo == null || !networkInfo.isConnected());
}
The problem is that if I have no Internet connection, I obtain the following in the Log:
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: KnoxVpnUidStorageknoxVpnSupported API value returned is false
So Android 5.1.1 are saying me that my application is slowing up my device and there are always error.
What's the problem? Thanks.
Upvotes: 2
Views: 9224
Reputation: 1191
Tis is the function that implements to check the Internet connection.
public boolean isOnline(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
android.net.NetworkInfo networkinfo = cm.getActiveNetworkInfo();
if (networkinfo != null && networkinfo.isConnected()) {
return true;
}
return false;
}
Upvotes: 5
Reputation: 1
Trying following code snippet:
private boolean hasNetworkConnection() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
return isConnected;
}
Upvotes: 0