Android系统下检测Wifi连接互联网是否正常的代码
/** |
* |
* 判断网络状态是否可用 |
* |
* @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连接互联网是否正常的代码的更多相关文章
- 【转载】Linux系统下命令行连接蓝牙设备 查看查找 蓝牙
Linux系统下命令行连接蓝牙设备 2018年11月26日 10:47:27 Zz笑对一切 阅读数:741 1.打开系统蓝牙 sudo service bluetooth start 1 进入bl ...
- (原)android系统下绑定Server的时候报MainActivity has leaked ServiceConnection的错误
今天在android系统下根据官方的demo代码,我们需要启动一个服务,并绑定,但在程序启动以后,老是报错: Activity MainActivity has leaked ServiceCon ...
- iTOP-iMX6开发板Android系统下LVDS和HDMI双屏异显方法
迅为iMX6 开发板 android 系统下 LVDS 和 HDMI 双屏异显的使用过程. 注意,iTOP-iMX6 开发板的 android 系统想要实现对 LVDS 和 HDMI 双屏异显功能的支 ...
- 我的Android进阶之旅------>Android检测wifi连接状态
今天要实现监听系统Wifi连接状态,下面代码简化后提取出来的,以备后用. step1. 编写BroadcastReceiver import android.content.BroadcastRece ...
- android系统下消息推送机制
一.推送方式简介: 当前随着移动互联网的不断加速,消息推送的功能越来越普遍,不仅仅是应用在邮件推送上了,更多的体现在手机的APP上.当我们开发需要和服务器交互的应用程序时,基本上都需要获取服务器端的数 ...
- Android系统下app测试功能点
一.安装卸载 1.验证app能否正常的安装启动运行,安装后的文件夹及文件是否写到了指定的目录里,卸载后相关文件是否清除 2.软件安装/卸载过程中意外情况的处理是否符合需求(如死机,重启,断电) 3.安 ...
- XP系统下建立WIFI热点让手机、电脑能上网
http://wenku.baidu.com/view/372c5b1fa300a6c30c229f42.html 这里记录xp系统下建立共享无线网络连接,若是支持手机设备上的话,网络适配器必须是wi ...
- 移动端UI自动化Appium测试——Android系统下使用uiautomator viewer查找元素
在利用Appium做自动化测试时,最重要的一步就是获取对应的元素值,根据元素来对对象进行对应的操作,如何获得对象元素呢?Appium Server Console其实提供了一个界面对话框&qu ...
- 怎样在win8系统下建立wifi热点
2012年10月26日,微软正式推出Windows 8操作系统,不少用户也都升级到了最新的Win8.大家知道.在Win7系统下,我们非常方便的就在命令提示符下建立了WIFI热点.那么Win8上是 ...
随机推荐
- CryptAPI 数字签名 与 Openssl 验证签名
这段时间要实现一个认证协议,分为客户端和服务器端,客户端使用windows操作系统,服务器端使用linux操作系统,在客户端下(windows),使用windows证书库中的签名证书对消息进行签名(使 ...
- 真实赛车3,SPEEDRUSH TV 第3季,第3阶段(第3天),直线加速赛
与其跳过,不如金币升级引擎和车身.因为后边紧跟一场计时赛.
- (转)扩展jquery easyui datagrid 之动态绑定列和数据
本文转载自:http://blog.csdn.net/littlewolf766/article/details/7336550 easyui datagrid 不支持动态加载列,上次使用的方法是自己 ...
- 【原创】Quartz代码详解
阅读目录 简单介绍 章节1:Quartz简单实例 章节2:Job.JobDetail.JobBuilder 章节3:Trigger.TriggerBuilder 章节4:Scheduler 章节5:J ...
- HTML常用标签(自用,可能不严谨,勿怪)
html标签中‘<’和‘>’默认被占用,如果想要显示出这些符号,就需要使用特殊字符来实现'<':使用<实现'>':使用>实现空格:html中再多的空格默 ...
- 为什么要用VisualSVN Server,而不用Subversion?
为什么要用VisualSVN Server,而不用Subversion? [SVN 服务器的选择] - 摘自网络 http://www.cnblogs.com/haoliansheng/archive ...
- 128. Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- MyEclipse背景色不伤眼+字体大小调节+代码格式化不换行
- BIP_开发案例10_BI Publisher报表国际化多语言的实现(案例)
2014-12-26 Created By BaoXinjian
- Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)
B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...