public boolean isConnectInternet() {

             ConnectivityManager conManager=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE );

             NetworkInfo networkInfo = conManager.getActiveNetworkInfo();

             if (networkInfo != null ){ // 注意,这个判断一定要的哦,要不然会出错

                       return networkInfo.isAvailable();

             }

             return false ;

}

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>