package in.mvpstarter.sample.util; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; public class NetworkUtil { /** * Returns true if the Throwable is an instance of RetrofitError with an * http status code equals to the given one. */ public static boolean isHttpStatusCode(Throwable throwable, int statusCode) { return throwable instanceof HttpException && ((HttpException) throwable).code() == statusCode; } public static boolean isNetworkConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.isConnectedOrConnecting(); } }