public static boolean isConnected(Context context) {
    if (!hasPermission(context, ACCESS_NETWORK_STATE)) {
      return true; // Assume we have a connection and try to upload.
    }
    ConnectivityManager cm = getSystemService(context, CONNECTIVITY_SERVICE);
    @SuppressLint("MissingPermission")
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
  }
public static boolean isConnected ( Context context ) { if ( ! hasPermission ( context , ACCESS_NETWORK_STATE ) ) { return true ; } ConnectivityManager cm = getSystemService ( context , CONNECTIVITY_SERVICE ) ; @ SuppressLint ( "MissingPermission" ) NetworkInfo activeNetwork = cm . getActiveNetworkInfo ( ) ; return activeNetwork != null && activeNetwork . isConnectedOrConnecting ( ) ; }
Returns {@code true} if the phone is connected to a network, or if we don't have the enough
permissions. Returns {@code false} otherwise.