Android判断网络连接
来源:互联网 发布:广州谷得网络 编辑:程序博客网 时间:2024/05/22 06:13
package com.ior.service;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
/** 检查联网状态 */
public class CheckNetworkState {
/** 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;
}
/**3G联网? */
public static boolean is3G(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打开? */
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);
}
/** 已连网络? */
public static boolean isNetworkAvailable(Context context) {
try {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager
.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isConnected();
} catch (Exception e) {
return false;
}
}
}
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
/** 检查联网状态 */
public class CheckNetworkState {
/** 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;
}
/**3G联网? */
public static boolean is3G(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打开? */
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);
}
/** 已连网络? */
public static boolean isNetworkAvailable(Context context) {
try {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager
.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isConnected();
} catch (Exception e) {
return false;
}
}
}
0 0
- android 判断网络连接
- android 判断网络连接
- android 判断网络连接
- android 判断网络连接
- 判断android网络连接
- android 判断网络连接
- Android--网络连接判断
- android判断网络连接
- android判断网络连接
- android判断网络连接
- Android网络连接判断
- Android网络连接判断
- android 网络连接判断
- Android网络连接判断
- Android 判断网络连接
- Android 判断网络连接
- Android判断网络连接
- Android---判断 网络连接
- Linux 内核模块的程序结构
- 关于NodeJs为什么要用mongoose操作mongodb
- 关于Android VerSionName版本控制问题
- poj 1125 Stockbroker Grapevine -- floyd 全源最短路
- html基础(二)
- Android判断网络连接
- iOS应用程序之如何获取版本号实现应用更新
- dpkg卸载.deb包
- CSS知识点总结
- LeetCode 316. Remove Duplicate Letters
- didAddSubview:、willRemoveSubview:、willMoveToSuperview:、didMoveToSuperview、willMoveToWindow:
- 欢迎使用CSDN-markdown编辑器
- 程序员必须知道的几个Git代码托管平台
- tomcat启动错误Error deploying web application directory,SSH框架启动错误