public static boolean getNetWorkInfo(Context cont) {try {ConnectivityManager manager = (ConnectivityManager) cont.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);if (manager == null) {return false;}NetworkInfo networkinfo = manager.getActiveNetworkInfo();if (networkinfo == null || !networkinfo.isAvailable()|| !networkinfo.isConnectedOrConnecting()) {return false;} else {// /如果有網路連接,再判斷一下是否可以正常上網,if (openUrl()) {// //正常return true;} else {return false;}}} catch (Exception e) {e.printStackTrace();return false;}}public static boolean openUrl() {String myString = "";try {URL url = new URL("HTTP://www.baidu.com/index.html");URLConnection urlCon = url.openConnection();urlCon.setConnectTimeout(1500);InputStream is = urlCon.getInputStream();BufferedInputStream bis = new BufferedInputStream(is);// 用ByteArrayBuffer緩衝ByteArrayBuffer baf = new ByteArrayBuffer(50);int current = 0;while ((current = bis.read()) != -1) {baf.append((byte) current);}myString = EncodingUtils.getString(baf.toByteArray(), "UTF-8");bis.close();is.close();} catch (Exception e) {e.printStackTrace();return false;}if (myString.indexOf("www.baidu.com") > -1) {return true;} else {return false;}}public boolean isWifiConnected(Context context) {if (context != null) {return getNetWorkInfo(context);}return false;}