aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/network/Network.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/network/Network.java')
-rw-r--r--main/src/cgeo/geocaching/network/Network.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/network/Network.java b/main/src/cgeo/geocaching/network/Network.java
index eb6a6ac..5a8cbb2 100644
--- a/main/src/cgeo/geocaching/network/Network.java
+++ b/main/src/cgeo/geocaching/network/Network.java
@@ -40,6 +40,9 @@ import org.apache.commons.lang3.StringUtils;
import org.json.JSONException;
import org.json.JSONObject;
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.net.Uri;
import java.io.File;
@@ -471,4 +474,19 @@ public abstract class Network {
return null;
}
+ /**
+ * Checks if the device has network connection.
+ *
+ * @param context
+ * context of the application, cannot be null
+ *
+ * @return <code>true</code> if the device is connected to the network.
+ */
+ public static boolean isNetworkConnected(Context context) {
+ ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo activeNetwork = conMan.getActiveNetworkInfo();
+
+ return activeNetwork != null && activeNetwork.isConnected();
+ }
+
}