/*
 * Copyright (C) 2016 Mateusz Widuch
 */
package eu.redray.trevie.utility;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Checks for all possible internet providers
 */
public class ConnectionDetector {
    /** Returns true if internet connection is available. */
    public static boolean isInternetConnectionAvailable(Context context){
        ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null)
        {
            NetworkInfo[] info = connectivity.getAllNetworkInfo();
            if (info != null)
                for (NetworkInfo anInfo : info)
                    if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
                        return true;
                    }
        }
        return false;
    }
}
@@ -144,16 +144,44 @@
 anager;%0A
+import android.net.Network;%0A
 import a
@@ -300,16 +300,23 @@
 %0A    /**
+%0A     *
  Returns
@@ -357,16 +357,21 @@
 ailable.
+%0A    
  */%0A    
@@ -438,16 +438,17 @@
 context)
+ 
 %7B%0A      
@@ -481,16 +481,23 @@
 ectivity
+Manager
  = (Conn
@@ -569,16 +569,142 @@
 RVICE);%0A
+%0A        // Use when API =%3E 21%0A        if (android.os.Build.VERSION.SDK_INT %3E= android.os.Build.VERSION_CODES.LOLLIPOP) %7B%0A    
         
@@ -719,16 +719,23 @@
 ectivity
+Manager
  != null
@@ -739,19 +739,588 @@
 ull)
-%0A        %7B%0A
+ %7B%0A                Network%5B%5D networks = connectivityManager.getAllNetworks();%0A                NetworkInfo networkInfo;%0A                for (Network network : networks) %7B%0A                    networkInfo = connectivityManager.getNetworkInfo(network);%0A                    if (networkInfo.getState().equals(NetworkInfo.State.CONNECTED)) %7B%0A                        return true;%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        // Use when API %3C 21%0A        else %7B%0A            if (connectivityManager != null) %7B%0A                @SuppressWarnings(%22deprecation%22)%0A    
     
@@ -1360,16 +1360,23 @@
 ectivity
+Manager
 .getAllN
@@ -1397,24 +1397,28 @@
             
+    
 if (info != 
@@ -1422,16 +1422,18 @@
 != null)
+ %7B
 %0A       
@@ -1433,32 +1433,36 @@
                 
+    
 for (NetworkInfo
@@ -1477,16 +1477,20 @@
 : info)%0A
+    
         
@@ -1573,32 +1573,36 @@
                 
+    
 return true;%0A   
@@ -1614,35 +1614,72 @@
             
+ 
-%7D%0A        %7D
+   %7D%0A                %7D%0A            %7D%0A        %7D%0A
 %0A        ret

Use non deprecated methods to check for connection on APIs 21+