import java.net.HttpURLConnection; /* 检查网络连接是否正常 */ public boolean checkInternetConnection (String strURL, String strEncoding) { /* 最多延时n秒若无应答则表示无法连接 */ int intTimeout = 5; try { HttpURLConnection urlConnection= null; URL url = new URL(strURL); urlConnection=(HttpURLConnection)url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.setDoInput(true); urlConnection.setRequestProperty ( "User-Agent","Mozilla/4.0"+ " (compatible; MSIE 6.0; Windows 2000)" ); urlConnection.setRequestProperty ("Content-type","text/html; charset="+strEncoding); urlConnection.setConnectTimeout(1000*intTimeout); urlConnection.connect(); if (urlConnection.getResponseCode() == 200) { return true; } else { return false; } } catch (Exception e) { e.printStackTrace(); return false; } }
有时候google二维码api ?chs="+
strWidth+"x"+strWidth+"&chl 不好用,可能是被墙了。可以用这个代替 ?s=5&d= (参数d和google里的chs一样)
// 判断是否为横屏 if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { } // 判断是否为竖屏 else if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { }