/* 测试手机是否具有联机Google API的联机能力 */
if(checkInternetConnection ("http://code.google.com/intl/zh-TW/apis/chart/","utf-8") )
{
bInternetConnectivity = true;
}
/* 检查网络联机是否正常 */
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;
}
}
/* 自定义BIG5转UTF-8 */
public String big52unicode(String strBIG5)
{
String strReturn="";
try
{
strReturn = new String(strBIG5.getBytes("big5"), "UTF-8");
}
catch (Exception e)
{
e.printStackTrace();
}
return strReturn;
}
/* 自定义UTF-8转BIG5 */
public String unicode2big5(String strUTF8)
{
String strReturn="";
try
{
strReturn = new String(strUTF8.getBytes("UTF-8"), "big5");
}
catch (Exception e)
{
e.printStackTrace();
}
return strReturn;
}