diff options
author | SammysHP <sven@sammyshp.de> | 2013-04-20 13:48:52 -0700 |
---|---|---|
committer | SammysHP <sven@sammyshp.de> | 2013-04-20 13:48:52 -0700 |
commit | d1f644bab3c674ea6a65a9560b6831cfb0cde499 (patch) | |
tree | 868bd3bcda0e463001ac53847432a6ab5955df64 /main | |
parent | b71d4bd03f8da774881d119c3ab55e16dc27f4d1 (diff) | |
parent | 705dc21ac799f786e6c7b76f9588ff22aa25a05f (diff) | |
download | cgeo-d1f644bab3c674ea6a65a9560b6831cfb0cde499.zip cgeo-d1f644bab3c674ea6a65a9560b6831cfb0cde499.tar.gz cgeo-d1f644bab3c674ea6a65a9560b6831cfb0cde499.tar.bz2 |
Merge pull request #2668 from donEgro/release
Handle no network when refreshing caches, fixes #708
Diffstat (limited to 'main')
-rw-r--r-- | main/src/cgeo/geocaching/cgeocaches.java | 5 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/network/Network.java | 18 |
2 files changed, 23 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index 30a18c5..e5176d5 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -1068,6 +1068,11 @@ public class cgeocaches extends AbstractListActivity implements FilteredActivity return; } + if (!Network.isNetworkConnected(getApplicationContext())) { + showToast(getString(R.string.err_server)); + return; + } + if (Settings.getChooseList() && type != CacheListType.OFFLINE) { // let user select list to store cache in new StoredList.UserInterface(this).promptForListSelection(R.string.list_title, 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(); + } + } |