333

来源:互联网 发布:linux能ghost吗 编辑:程序博客网 时间:2024/05/21 15:47

import android.content.Context;import android.net.ConnectivityManager;import android.net.NetworkInfo;/** * Created by Administrator on 2017/10/9. */public class NetWorkUtil {    public static boolean isNetworkAvailable(Context context){        boolean hasWifoCon = false;        boolean hasMobileCon = false;        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);        NetworkInfo[] netInfos = cm.getAllNetworkInfo();        for (NetworkInfo net : netInfos){            String type = net.getTypeName();            if(type.equalsIgnoreCase("WIFI")){                if(!net.isConnected()){                    hasWifoCon = true;                }            }            if(type.equalsIgnoreCase("MOBILE")){                if(!net.isConnected()){                    hasMobileCon = true;                }            }        }        return hasMobileCon || hasWifoCon;    }}
原创粉丝点击