判断网络是否连接工具类
来源:互联网 发布:韩顺平java spring视频 编辑:程序博客网 时间:2024/06/04 23:13
/**
* Created by a on 2014/5/18.
*
* 和网络相关的工具类
*
* isConnected(Context context) 判断网络是否连接
* isWifi(Context context) 判断是否是wifi连接
* openSetting(Activity activity) 打开网络设置界面
*
* @author zhengjiao
*
*/
public class NetUtils {
private NetUtils()
{
/* cannot be instantiated */
throw new UnsupportedOperationException("cannot be instantiated");
}
/**
* 判断网络是否连接
*
* @param context
* @return
*/
public static boolean isConnected(Context context)
{
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (null != connectivity)
{
NetworkInfo info = connectivity.getActiveNetworkInfo();
if (null != info && info.isConnected())
{
if (info.getState() == NetworkInfo.State.CONNECTED)
{
return true;
}
}
}
return false;
}
/**
* 判断是否是wifi连接
*/
public static boolean isWifi(Context context)
{
ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null)
return false;
return cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI;
}
/**
* 打开网络设置界面
*/
public static void openSetting(Activity activity)
{
Intent intent = new Intent("/");
ComponentName cm = new ComponentName("com.android.settings","com.android.settings.WirelessSettings");
intent.setComponent(cm);
intent.setAction("android.intent.action.VIEW");
activity.startActivityForResult(intent, 0);
}
}
- 判断网络是否连接工具类
- 一个判断网络是否连接的工具类
- 封装工具类,判断是否连接网络,请求数据
- 判断是否连接网络
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接,
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 【Get深一度】谐振腔中的电场(E Field[V_per_m])与磁场(H field[A_per_m])分布
- java.lang.IllegalArgumentException: column '_id' does not exist 解决方法
- maven安装本地jar包
- android、ios与服务器端php使用rsa加密解密通讯
- freemarker常见语法大全
- 判断网络是否连接工具类
- Sublime text3 增加插件
- 【zzuli-oj】-1895-985的0-1串难题(思维,好)
- Candence更新Allegro的Ref到OrCAD的步骤
- 数据库三大范式及sql的基础
- 序列化反序列二叉树
- java中pattern和matcher详解
- HDU 1536 S-Nim
- Log打印工具类