package com.zhimai.websocket.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Explain：
 * Created on 2020/9/25.
 *
 * @author zhangshenglong
 */
public class NetWorkUtils {
    public static boolean isOnline(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (cm == null) {
            return false;
        }
        try {
            return cm.getActiveNetworkInfo().isAvailable();
        }catch (Exception e){
            return false;
        }
    }

    public static boolean isOffline(Context context) {
        return false == isOnline(context);
    }
}
