/**
 *
 * 判断网络状态是否可用
 *
 * @return true: 网络可用 ; false: 网络不可用
 */
  
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;
}
/* 检查网络联机是否正常 */
public boolean checkInternetConnection(String strURL, String strEncoding)
{
    /* 最多延时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转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;
}

Android系统下检测Wifi连接互联网是否正常的代码的更多相关文章

  1. 【转载】Linux系统下命令行连接蓝牙设备 查看查找 蓝牙

    Linux系统下命令行连接蓝牙设备 2018年11月26日 10:47:27 Zz笑对一切 阅读数:741   1.打开系统蓝牙 sudo service bluetooth start 1 进入bl ...

  2. (原)android系统下绑定Server的时候报MainActivity has leaked ServiceConnection的错误

    今天在android系统下根据官方的demo代码,我们需要启动一个服务,并绑定,但在程序启动以后,老是报错:   Activity MainActivity has leaked ServiceCon ...

  3. iTOP-iMX6开发板Android系统下LVDS和HDMI双屏异显方法

    迅为iMX6 开发板 android 系统下 LVDS 和 HDMI 双屏异显的使用过程. 注意,iTOP-iMX6 开发板的 android 系统想要实现对 LVDS 和 HDMI 双屏异显功能的支 ...

  4. 我的Android进阶之旅------>Android检测wifi连接状态

    今天要实现监听系统Wifi连接状态,下面代码简化后提取出来的,以备后用. step1. 编写BroadcastReceiver import android.content.BroadcastRece ...

  5. android系统下消息推送机制

    一.推送方式简介: 当前随着移动互联网的不断加速,消息推送的功能越来越普遍,不仅仅是应用在邮件推送上了,更多的体现在手机的APP上.当我们开发需要和服务器交互的应用程序时,基本上都需要获取服务器端的数 ...

  6. Android系统下app测试功能点

    一.安装卸载 1.验证app能否正常的安装启动运行,安装后的文件夹及文件是否写到了指定的目录里,卸载后相关文件是否清除 2.软件安装/卸载过程中意外情况的处理是否符合需求(如死机,重启,断电) 3.安 ...

  7. XP系统下建立WIFI热点让手机、电脑能上网

    http://wenku.baidu.com/view/372c5b1fa300a6c30c229f42.html 这里记录xp系统下建立共享无线网络连接,若是支持手机设备上的话,网络适配器必须是wi ...

  8. 移动端UI自动化Appium测试——Android系统下使用uiautomator viewer查找元素

        在利用Appium做自动化测试时,最重要的一步就是获取对应的元素值,根据元素来对对象进行对应的操作,如何获得对象元素呢?Appium Server Console其实提供了一个界面对话框&qu ...

  9. 怎样在win8系统下建立wifi热点

     2012年10月26日,微软正式推出Windows 8操作系统,不少用户也都升级到了最新的Win8.大家知道.在Win7系统下,我们非常方便的就在命令提示符下建立了WIFI热点.那么Win8上是 ...

随机推荐

  1. row_number()over(order by id) SQL顺序排列

    select *,row_number()over(order by id) as number_id from [dbo].tb_pccw20140213

  2. HackerRank "Permutation game"

    A typical game theory problem - Recursion + Memorized Searchhttp://justprogrammng.blogspot.com/2012/ ...

  3. Zabbix agent on Microsoft Windows

    1.在Windows上创建目录: C:\Windows\zabbix\ 2.下载安装包并解压到新建的目录 3.下载地址:http://www.zabbix.com/downloads/3.0.0/za ...

  4. [tty与uart]3.tty驱动分析

    转自:http://www.wowotech.net/linux_kenrel/183.html 目录: 1 首先分析设备驱动的注册 1.1 uart_register_driver分析 1.2 tt ...

  5. (WCF) WCF and Service Debug

    需要做一个多程序间的通讯,采用WCF和WCF Service是目前的选择. 需求:和产品进行通讯,和用户有交互操作,并将最后结果传送个DB 基本思路: 1. 用WPF客户端程序和产品进行通讯,获取必要 ...

  6. (C#) 创建单元测试(Unit Test).

    在VS2012中的右键中没有发现"Create Unit Test" 选项,原来需要安装个补丁: https://visualstudiogallery.msdn.microsof ...

  7. VALGRIND

    系统编程中一个重要的方面就是有效地处理与内存相关的问题.你的工作越接近系统,你就需要面对越多的内存问题.有时这些问题非常琐碎,而更多时候它会演变成一个调试内存问题的恶梦.所以,在实践中会用到很多工具来 ...

  8. 工作中Linux常用命令

    rpm -qa|grep -i mysql rpm -ev mysql-server-5.1.73-5.el6_6.x86_64 如果报: error: Failed dependencies: li ...

  9. DG_Oracle DataGuard作用和概念(概念)

    2014-06-03 Created By BaoXinjian  

  10. 停止某个机房所有机器上包的脚本 pack_idc_stop.py

    一.初衷: 鉴于公司的进程包package都是冗余多点部署的,一般一个idc机房有多台机器部署同一个package.当机房网络出问题的时候,我们不得不查到本机房部署了哪些package,并在包发布系统 ...