中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Android系統(tǒng)下檢測Wifi連接互聯(lián)網(wǎng)是否正常的代碼

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
/**
 *
 * 判斷網(wǎng)絡(luò)狀態(tài)是否可用
 *
 * @return true: 網(wǎng)絡(luò)可用 ; false: 網(wǎng)絡(luò)不可用
 */
  
public boolean isConnectInternet()
{
    ConnectivityManager conManager = (ConnectivityManager) test.this
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = conManager.getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnected())
    {
        return false;
    }
    if (networkInfo.isConnected())
    {
        return true;
    }
    return false;
}
/* 檢查網(wǎng)絡(luò)聯(lián)機是否正常 */
public boolean checkInternetConnection(String strURL, String strEncoding)
{
    /* 最多延時n秒若無響應(yīng)則表示無法聯(lián)機 */
    int intTimeout = 10;
    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
        {
            Log.d("getResponseCode=", urlConnection.getResponseMessage());
  
            return false;
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
        Log.d("emessage", e.getMessage());
        return false;
    }
}
  
/* 自定義BIG5轉(zhuǎn)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轉(zhuǎn)BIG5 */
public String unicode2big5(String strUTF8)
{
    String strReturn = "";
    try
    {
        strReturn = new String(strUTF8.getBytes("UTF-8"), "big5");
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    return strReturn;
}

標簽: 網(wǎng)絡(luò)

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:Android系統(tǒng)上拉刷新功能的實現(xiàn)

下一篇:Java JDBC 小例子