use of android.net.ConnectivityManager in project QLibrary by DragonsQC.
the class NetStateUtils method isNetworkConnected.
/**
* 判断是否有网络连接
*
* @return 是否有网络连接
*/
public static boolean isNetworkConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null) {
return mNetworkInfo.isAvailable();
}
}
return false;
}
use of android.net.ConnectivityManager in project CloudReader by youlookwhat.
the class CheckNetwork method isNetworkConnected.
/**
* 判断网络是否连通
*/
public static boolean isNetworkConnected(Context context) {
try {
if (context != null) {
@SuppressWarnings("static-access") ConnectivityManager cm = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
return info != null && info.isConnected();
} else {
/**如果context为空,就返回false,表示网络未连接*/
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
use of android.net.ConnectivityManager in project CloudReader by youlookwhat.
the class CheckNetwork method isNetworkConnected.
/**
* 判断网络是否连通
*/
public static boolean isNetworkConnected(Context context) {
try {
if (context != null) {
@SuppressWarnings("static-access") ConnectivityManager cm = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
return info != null && info.isConnected();
} else {
/**如果context为空,就返回false,表示网络未连接*/
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
use of android.net.ConnectivityManager in project CloudReader by youlookwhat.
the class CheckNetwork method isWifiConnected.
public static boolean isWifiConnected(Context context) {
if (context != null) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
return info != null && (info.getType() == ConnectivityManager.TYPE_WIFI);
} else {
/**如果context为null就表示为未连接*/
return false;
}
}
use of android.net.ConnectivityManager in project android_frameworks_base by ResurrectionRemix.
the class NetworkManagementService method initDataInterface.
private void initDataInterface() {
if (!TextUtils.isEmpty(mDataInterfaceName)) {
return;
}
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
LinkProperties linkProperties = cm.getLinkProperties(ConnectivityManager.TYPE_MOBILE);
if (linkProperties != null) {
mDataInterfaceName = linkProperties.getInterfaceName();
}
}
Aggregations