use of android.net.NetworkInfo in project android-common by Trinea.
the class NetWorkUtils method getNetworkType.
/**
* Get network type
*
* @param context
* @return
*/
public static int getNetworkType(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager == null ? null : connectivityManager.getActiveNetworkInfo();
return networkInfo == null ? -1 : networkInfo.getType();
}
use of android.net.NetworkInfo in project android-common by Trinea.
the class NetWorkUtils method getNetworkTypeName.
/**
* Get network type name
*
* @param context
* @return
*/
public static String getNetworkTypeName(Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo;
String type = NETWORK_TYPE_DISCONNECT;
if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
return type;
}
;
if (networkInfo.isConnected()) {
String typeName = networkInfo.getTypeName();
if ("WIFI".equalsIgnoreCase(typeName)) {
type = NETWORK_TYPE_WIFI;
} else if ("MOBILE".equalsIgnoreCase(typeName)) {
String proxyHost = android.net.Proxy.getDefaultHost();
type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G) : NETWORK_TYPE_WAP;
} else {
type = NETWORK_TYPE_UNKNOWN;
}
}
return type;
}
use of android.net.NetworkInfo in project MVCHelper by LuckyJayce.
the class NetworkUtils method hasNetwork.
/**
* 是否有网络连接
*
* @param paramContext
* @return
*/
public static boolean hasNetwork(Context paramContext) {
try {
ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo localNetworkInfo = localConnectivityManager.getActiveNetworkInfo();
if ((localNetworkInfo != null) && (localNetworkInfo.isAvailable()))
return true;
} catch (Throwable localThrowable) {
localThrowable.printStackTrace();
}
return false;
}
use of android.net.NetworkInfo in project MVCHelper by LuckyJayce.
the class NetworkUtils method isWifi.
/**
* {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param context
* @return
*/
public static boolean isWifi(Context context) {
ConnectivityManager connectMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectMgr.getActiveNetworkInfo();
if (info == null)
return false;
return info.getType() == ConnectivityManager.TYPE_WIFI;
}
use of android.net.NetworkInfo in project Signal-Android by WhisperSystems.
the class MmsRadio method isConnected.
private boolean isConnected() {
NetworkInfo info = connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS);
Log.w("MmsRadio", "Connected: " + info);
if ((info == null) || (info.getType() != TYPE_MOBILE_MMS) || !info.isConnected())
return false;
return true;
}
Aggregations