|
* @return true: 网络可用 ; false: 网络不可用 |
public boolean isConnectInternet() |
ConnectivityManager conManager = (ConnectivityManager) test.this |
.getSystemService(Context.CONNECTIVITY_SERVICE); |
NetworkInfo networkInfo = conManager.getActiveNetworkInfo(); |
if (networkInfo == null || !networkInfo.isConnected()) |
if (networkInfo.isConnected()) |
public boolean checkInternetConnection(String strURL, String strEncoding) |
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); |
if (urlConnection.getResponseCode() == 200) |
Log.d("getResponseCode=", urlConnection.getResponseMessage()); |
Log.d("emessage", e.getMessage()); |
public String big52unicode(String strBIG5) |
strReturn = new String(strBIG5.getBytes("big5"), "UTF-8"); |
public String unicode2big5(String strUTF8) |
strReturn = new String(strUTF8.getBytes("UTF-8"), "big5"); |
|
|
|