use of android.net.ConnectivityManager in project android by owncloud.
the class ConnectivityUtils method isAppConnectedViaWiFi.
public static boolean isAppConnectedViaWiFi(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean result = cm != null && cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI && cm.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED;
Log_OC.d(TAG, "is AppConnectedViaWifi returns " + result);
return result;
}
use of android.net.ConnectivityManager in project superCleanMaster by joyoyao.
the class AppUtil method isMobile.
/**
* 判断当前网络是否是移动数据网络.
*
* @param context the context
* @return boolean
*/
public static boolean isMobile(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
return true;
}
return false;
}
use of android.net.ConnectivityManager in project ignition by mttkay.
the class IgnitedHttp method updateProxySettings.
/**
* Updates the underlying HTTP client's proxy settings with what the user has entered in the APN
* settings. This will be called automatically if {@link #listenForConnectivityChanges(Context)}
* has been called. <b>This requires the {@link Manifest.permission#ACCESS_NETWORK_STATE}
* permission</b>.
*
* @param context
* the current context
*/
public void updateProxySettings(Context context) {
if (context == null) {
return;
}
HttpParams httpParams = httpClient.getParams();
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nwInfo = connectivity.getActiveNetworkInfo();
if (nwInfo == null) {
return;
}
Log.i(LOG_TAG, nwInfo.toString());
if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
String proxyHost = Proxy.getHost(context);
if (proxyHost == null) {
proxyHost = Proxy.getDefaultHost();
}
int proxyPort = Proxy.getPort(context);
if (proxyPort == -1) {
proxyPort = Proxy.getDefaultPort();
}
if (proxyHost != null && proxyPort > -1) {
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
} else {
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
}
} else {
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
}
}
use of android.net.ConnectivityManager in project QLibrary by DragonsQC.
the class NetStateUtils method isWifiConnected.
/**
* 判断WIFI网络是否连接
*
* @return WIFI是否连接
*/
public static boolean isWifiConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mWiFiNetworkInfo != null && mWiFiNetworkInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
return false;
}
use of android.net.ConnectivityManager in project QLibrary by DragonsQC.
the class NetStateUtils method getConnectedType.
/**
* 获取当前的网络状态
* -1:没有网络,1:WIFI网络,2:wap网络,3:net网络
*
* @return 当前的网络状态
*/
public static int getConnectedType(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
return mNetworkInfo.getType();
}
}
return -1;
}
Aggregations