Android examples for android.net:ConnectivityManager
is Network Connected
import android.content.Context; import android.location.LocationManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.telephony.TelephonyManager; import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ public static boolean isNetworkConnected(Context context) { if (context != null) { ConnectivityManager mConnectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mNetworkInfo = mConnectivityManager .getActiveNetworkInfo(); if (mNetworkInfo == null) { return false; }//from w w w. jav a2s .c o m return (mNetworkInfo.getState() == NetworkInfo.State.CONNECTED); } return false; } }