android 入门进修条记 查抄网络毗连是否正常 判定是否为横屏

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) { }


 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/8430.html