权限要求:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
//context上下文 如果返回值不为空则可以联网
public static boolean isNetworkConn(Context context)
{
boolean flag = false;
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = manager.getActiveNetworkInfo();
if (info!=null) {
return info.isConnected();
}
return flag;
}