@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
req
You should use a broadcast receiver as mentioned in other SO answers, but since you have asked how to do this otherwise, here you go:
* Checks for an existing network connectivity
*
* @param context
* The {@link Context} which is needed to tap
* {@link Context#CONNECTIVITY_SERVICE}
* @return True if network connection is available
*/
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
Will need additional permission to be specified in the manifest file