一、判断网络连接是否可用(返回true表示网络可用,false为不可用)

 public static boolean checkNetworkAvailable(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
NetworkInfo netWorkInfo = info[i];
if (netWorkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
return true;
} else if (netWorkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
return true;
}
}
}
}
}
return false;
}

二、判断GPS是否打开

 public static boolean isGpsEnabled(Context context) {
LocationManager lm = ((LocationManager) context
.getSystemService(Context.LOCATION_SERVICE));
List<String> accessibleProviders = lm.getProviders(true);
return accessibleProviders != null && accessibleProviders.size() > 0;
}

三、判断WIFI是否打开

 public static boolean isWifiEnabled(Context context) {
ConnectivityManager mgrConn = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
TelephonyManager mgrTel = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
return ((mgrConn.getActiveNetworkInfo() != null && mgrConn
.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED) || mgrTel
.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
}

四、判断是否是3G网络

 public static boolean is3rd(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkINfo = cm.getActiveNetworkInfo();
if (networkINfo != null
&& networkINfo.getType() == ConnectivityManager.TYPE_MOBILE) {
return true;
}
return false;
}

五、判断是wifi还是3g网络,用户的体现性在这里了,wifi就可以建议下载或者在线播放。

 public static boolean isWifi(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkINfo = cm.getActiveNetworkInfo();
if (networkINfo != null
&& networkINfo.getType() == ConnectivityManager.TYPE_WIFI) {
return true;
}
return false;
}

android中判断网络连接是否可用的更多相关文章

  1. Android中判断网络连接是否可用及监控网络状态

    Android中判断网络连接是否可用及监控网络状态 作者: 字体:[增加 减小] 类型:转载 获取网络信息需要在AndroidManifest.xml文件中加入相应的权限,接下来详细介绍Android ...

  2. Android中判断网络是否连接并提示设置

    /** * 判断网络是否连通 * @param context * @return */ public static boolean isNetworkConnected(Context contex ...

  3. android中 检查网络连接状态的变化,无网络时跳转到设置界面

    1:在AndroidManifest.xml中加一个声明 <receiver android:name="NetCheckReceiver">    <inten ...

  4. Android 中判断网络状态

    首先在AndroidManifest.xml添加权限 <uses-permission android:name="android.permission.ACCESS_NETWORK_ ...

  5. android判断网络连接状态、联网类型、运营商

    /** * 获取上网方式 * * @param mContext * @return */ public static String getNetType(Context mContext) { St ...

  6. HttpUtil 【判断网络连接的封装类】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 该封装类主要包括以下功能: 判断是否有网络连接.判断是否有可用的网络连接: 判断是否是3G网络.判断mobile网络是否可用: 判断 ...

  7. Win8 app判断网络连接状态

    Win8 app判断网络连接状态 NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged; ...

  8. c#判断网络连接状态示例代码

    使用c#判断网络连接状态的代码. 代码: public partial class Form1 : Form { [DllImport() == true) { label1.Text = " ...

  9. 负载均衡服务TCP端口健康检查成功,为什么在后端业务日志中出现网络连接异常信息?

    负载均衡服务TCP端口健康检查成功,为什么在后端业务日志中出现网络连接异常信息? 原文: https://help.aliyun.com/document_detail/127193.html?spm ...

随机推荐

  1. Linux 中常见的命令行,持续更新

    1.添加自己的环境变量 root@adonis:~# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin r ...

  2. ThinkPHP魔术方法

    我们在使用thinkphp开发系统的时候,有时候会用到getById('1')这个方法快速的获取一条信息的内容,比用where(" id =1 ")->find();好用多了 ...

  3. I’ve seen the world,lit it up as my stage now

    I've seen the world,lit it up as my stage now 阅尽繁华 点亮红尘做舞台 Channeling angels in,the new age now 粉末登场 ...

  4. 【C语言入门教程】5.4 递归

    递归函数 是能够直接或通过另一个函数间接调用自身的函数,调用自身的方法称为递归调用.递归调用的本质是使用同一算法将复杂的问题不断化简,直到该问题解决. 例如求斐波那契数列的某一项算法适用于递归函数实现 ...

  5. html5的触摸事件

    1.触摸事件有哪些 touchstart,touchmove,touchend 2.分别什么时候触发 touchstart事件:当手指触摸屏幕时候触发,即使已经有一个手指放在屏幕上也会触发. touc ...

  6. HDU 2861 四维dp打表

    Patti and Terri run a bar in which there are 15 stools. One day, Darrell entered the bar and found t ...

  7. IOI2015 Boxes

    Description 给出一个环形,n个点,每次只能访问k个点,求最短距离. Sol 贪心. CCF的题解. 首先只会最多走一趟环形,根据抽屉原理,如果一边不足k个才会到另一边,所以对于第二次以上的 ...

  8. OpenGL官方教程——着色器语言概述

    OpenGL官方教程——着色器语言概述 OpenGL官方教程——着色器语言概述 可编程图形硬件管线(流水线) 可编程顶点处理器 可编程几何处理器 可编程片元处理器 语言 可编程图形硬件管线(流水线) ...

  9. Java验证码识别解决方案

    建库,去重,切割,识别. package edu.fzu.ir.test; import java.awt.Color; import java.awt.image.BufferedImage; im ...

  10. linux awk, xargs

    awk , 很赞的教程:http://coolshell.cn/articles/9070.html xargs, http://blog.csdn.net/andy572633/article/de ...