Java tutorial
//package com.java2s; //License from project: LGPL import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { /** * checks if there is WI-FI or network connection available * @param currentActivity * @return */ public static boolean isInternetAvailable(Context currentActivity) { final ConnectivityManager conectivityManager = (ConnectivityManager) currentActivity .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = conectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { if (networkInfo.isConnected()) { return true; } } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { if (networkInfo.isConnected()) { return true; } } } return false; } }