首页 > 代码库 > Android网络状态判断 wifi mobile
Android网络状态判断 wifi mobile
/**
* 网络状态 wifi mobile
*
* @author jiangbing
*
*/
public class NetworkUtils {
/**
* 判断当前是否 网络连接 (是否有效的连接)不分wifi mobile
*/
public static boolean isConnectdeAvailable(Context context) {
try {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager != null) {
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
if (networkInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
} catch (Exception e) {
return false;
}
return false;
}
/**
* 判断当前是否 WIFI网络
*/
public static boolean isWIFIConnectde(Context context) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager != null) {
NetworkInfo networkInfo = manager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo != null && networkInfo.isConnected()) {
return true;
}
}
return false;
}
/**
* 判断当前是否 WIFI网络 (是否有效的连接)
*/
public static boolean isWIFIConnectdeAvailable(Context context) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager != null) {
NetworkInfo networkInfo = manager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo != null && networkInfo.isConnected()) {
if (networkInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}
/**
* 判断当前网络是否移动网络
*
* @param context
* @return boolean
*/
public static boolean isMobileConnectde(Context context) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager != null) {
NetworkInfo networkInfo = manager
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (networkInfo != null && networkInfo.isConnected()) {
return true;
}
}
return false;
}
/**
* 判断当前网络是否移动网络 (是否有效的连接)
*
* @param context
* @return boolean
*/
public static boolean isMobileConnectdeAvailable(Context context) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager != null) {
NetworkInfo networkInfo = manager
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (networkInfo != null && networkInfo.isConnected()) {
if (networkInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}
/**
* 打开网络设置界面
*/
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);
}
/**
* Gps是否打开
*
* @param context
* @return
*/
public static boolean isGpsEnabled(Context context) {
LocationManager locationManager = ((LocationManager) context
.getSystemService(Context.LOCATION_SERVICE));
List<String> accessibleProviders = locationManager.getProviders(true);
return accessibleProviders != null && accessibleProviders.size() > 0;
}
}
* 网络状态 wifi mobile
*
* @author jiangbing
*
*/
public class NetworkUtils {
/**
* 判断当前是否 网络连接 (是否有效的连接)不分wifi mobile
*/
public static boolean isConnectdeAvailable(Context context) {
try {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager != null) {
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
if (networkInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
} catch (Exception e) {
return false;
}
return false;
}
/**
* 判断当前是否 WIFI网络
*/
public static boolean isWIFIConnectde(Context context) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager != null) {
NetworkInfo networkInfo = manager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo != null && networkInfo.isConnected()) {
return true;
}
}
return false;
}
/**
* 判断当前是否 WIFI网络 (是否有效的连接)
*/
public static boolean isWIFIConnectdeAvailable(Context context) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager != null) {
NetworkInfo networkInfo = manager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo != null && networkInfo.isConnected()) {
if (networkInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}
/**
* 判断当前网络是否移动网络
*
* @param context
* @return boolean
*/
public static boolean isMobileConnectde(Context context) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager != null) {
NetworkInfo networkInfo = manager
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (networkInfo != null && networkInfo.isConnected()) {
return true;
}
}
return false;
}
/**
* 判断当前网络是否移动网络 (是否有效的连接)
*
* @param context
* @return boolean
*/
public static boolean isMobileConnectdeAvailable(Context context) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager != null) {
NetworkInfo networkInfo = manager
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (networkInfo != null && networkInfo.isConnected()) {
if (networkInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}
/**
* 打开网络设置界面
*/
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);
}
/**
* Gps是否打开
*
* @param context
* @return
*/
public static boolean isGpsEnabled(Context context) {
LocationManager locationManager = ((LocationManager) context
.getSystemService(Context.LOCATION_SERVICE));
List<String> accessibleProviders = locationManager.getProviders(true);
return accessibleProviders != null && accessibleProviders.size() > 0;
}
}
Android网络状态判断 wifi mobile
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。