use of android.net.ConnectivityManager 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.ConnectivityManager in project Fairphone by Kwamecorp.
the class FairphoneUpdater method isWiFiEnabled.
private boolean isWiFiEnabled() {
ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
return isWifi;
}
use of android.net.ConnectivityManager 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.ConnectivityManager 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.ConnectivityManager in project Signal-Android by WhisperSystems.
the class LegacyMmsConnection method checkRouteToHost.
@SuppressWarnings("TryWithIdenticalCatches")
protected static boolean checkRouteToHost(Context context, String host, boolean usingMmsRadio) throws IOException {
InetAddress inetAddress = InetAddress.getByName(host);
if (!usingMmsRadio) {
if (inetAddress.isSiteLocalAddress()) {
throw new IOException("RFC1918 address in non-MMS radio situation!");
}
Log.w(TAG, "returning vacuous success since MMS radio is not in use");
return true;
}
if (inetAddress == null) {
throw new IOException("Unable to lookup host: InetAddress.getByName() returned null.");
}
byte[] ipAddressBytes = inetAddress.getAddress();
if (ipAddressBytes == null) {
Log.w(TAG, "resolved IP address bytes are null, returning true to attempt a connection anyway.");
return true;
}
Log.w(TAG, "Checking route to address: " + host + ", " + inetAddress.getHostAddress());
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
try {
final Method requestRouteMethod = manager.getClass().getMethod("requestRouteToHostAddress", Integer.TYPE, InetAddress.class);
final boolean routeToHostObtained = (Boolean) requestRouteMethod.invoke(manager, MmsRadio.TYPE_MOBILE_MMS, inetAddress);
Log.w(TAG, "requestRouteToHostAddress(" + inetAddress + ") -> " + routeToHostObtained);
return routeToHostObtained;
} catch (NoSuchMethodException nsme) {
Log.w(TAG, nsme);
} catch (IllegalAccessException iae) {
Log.w(TAG, iae);
} catch (InvocationTargetException ite) {
Log.w(TAG, ite);
}
final int ipAddress = Conversions.byteArrayToIntLittleEndian(ipAddressBytes, 0);
final boolean routeToHostObtained = manager.requestRouteToHost(MmsRadio.TYPE_MOBILE_MMS, ipAddress);
Log.w(TAG, "requestRouteToHost(" + ipAddress + ") -> " + routeToHostObtained);
return routeToHostObtained;
}
Aggregations