You can follow Erel's video tutorial on how to setup your eclipse platform and make a library.
When you have done settings the first thing up, you can copy the following code and paste in your eclipse project:
I tested this code some time ago: it should work, but i'm not sure about wifi though.
public boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) ba.applicationcontext.getSystemService(ba.applicationcontext.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null;
}
Don't forget to add "android.permission.ACCESS_NETWORK_STATE" permission
Or this code:
public boolean haveNetworkConnection() {
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager) ba.applicationcontext.getSystemService(ba.applicationcontext.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
}
return haveConnectedWifi || haveConnectedMobile;
}
You can make a library to your needs, for example custom library and everytime you need an new extension, you can edit and add new code to the library.
Tomas