0

Does Android set & manages some system/environment variables, and how acces & manage them? Is there a full list of those variable somewhere? For instance, in my case, what would be usefull, would be some "network yes/no var" like: NETWORK_AVALAIBLE, WIFI_AVAILABLE, 3G_AVAILABLE, aso...

Steph68
  • 197
  • 4
  • 13
  • Have you went through these links http://stackoverflow.com/questions/4238921/android-detect-whether-there-is-an-internet-connection-available and http://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-timeouts – BBdev Nov 19 '12 at 10:44
  • I checked the related topics when creating mine and made a search yep, but the search criteria are too common. – Steph68 Nov 19 '12 at 12:30

1 Answers1

2

The following code will be helpful to check connectivity.

ConnectivityManager manager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mobile = manager
        .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo wifi = manager
        .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (!wifi.isAvailable() && !mobile.isAvailable()) {
    return false;
} else {
    return true;
}

also add following code to manifest file

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

You can always refer android developer site for this type of questions

SKT
  • 1,821
  • 1
  • 20
  • 32
  • @Steph68 If this answer was useful you could help it by marking it as answer :) – SKT Nov 19 '12 at 13:15