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; } }