NetWorkUtils网络工具类

public class NetWorkUtils {

public static boolean isNetworkConnected(Context context) {
    //获取网络连接状态管理器
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    //得到网络信息
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info != null) {

        return info.isAvailable();
    }

    return false;
}

}

猜你喜欢

转载自blog.csdn.net/qq_42809175/article/details/86430608