use of android.net.NetworkInfo in project android by cSploit.
the class Network method isConnectivityAvailable.
public static boolean isConnectivityAvailable(Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = manager.getActiveNetworkInfo();
return info != null && info.isConnected();
}
use of android.net.NetworkInfo in project GeekNews by codeestX.
the class SystemUtil method isMobileNetworkConnected.
/**
* 检查手机网络(4G/3G/2G)是否连接
*/
public static boolean isMobileNetworkConnected() {
ConnectivityManager connectivityManager = (ConnectivityManager) App.getInstance().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mobileNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
return mobileNetworkInfo != null;
}
use of android.net.NetworkInfo in project android-app by eoecn.
the class APNManager method getDefaultNetworkType.
public int getDefaultNetworkType() {
int networkType = -1;
ConnectivityManager connectivity = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
} else {
// wifi network have priority
NetworkInfo wifiNetworkInfo = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (wifiNetworkInfo != null && wifiNetworkInfo.getState() == NetworkInfo.State.CONNECTED) {
return ConnectivityManager.TYPE_WIFI;
}
NetworkInfo[] info = connectivity.getAllNetworkInfo();
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
// use first available network
networkType = info[i].getType();
break;
}
}
}
return networkType;
}
use of android.net.NetworkInfo in project android-job by evernote.
the class Device method getNetworkType.
@NonNull
public static JobRequest.NetworkType getNetworkType(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
return JobRequest.NetworkType.ANY;
}
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null && telephonyManager.isNetworkRoaming()) {
return JobRequest.NetworkType.CONNECTED;
}
boolean metered = ConnectivityManagerCompat.isActiveNetworkMetered(connectivityManager);
return metered ? JobRequest.NetworkType.NOT_ROAMING : JobRequest.NetworkType.UNMETERED;
}
use of android.net.NetworkInfo in project Android-Boilerplate by hitherejoe.
the class NetworkUtil method isNetworkConnected.
public static boolean isNetworkConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}
Aggregations