Search in sources :

Example 76 with ConnectivityManager

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;
}
Also used : ConnectivityManager(android.net.ConnectivityManager)

Example 77 with ConnectivityManager

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;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 78 with ConnectivityManager

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);
    }
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) HttpHost(org.apache.http.HttpHost)

Example 79 with ConnectivityManager

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;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 80 with ConnectivityManager

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;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Aggregations

ConnectivityManager (android.net.ConnectivityManager)379 NetworkInfo (android.net.NetworkInfo)275 Context (android.content.Context)14 TelephonyManager (android.telephony.TelephonyManager)14 Intent (android.content.Intent)11 RemoteException (android.os.RemoteException)11 Test (org.junit.Test)11 WifiManager (android.net.wifi.WifiManager)9 Method (java.lang.reflect.Method)9 Network (android.net.Network)8 IOException (java.io.IOException)8 PackageManager (android.content.pm.PackageManager)7 UserManager (android.os.UserManager)7 SharedPreferences (android.content.SharedPreferences)6 NetworkCapabilities (android.net.NetworkCapabilities)6 Activity (android.app.Activity)5 ApplicationInfo (android.content.pm.ApplicationInfo)5 IPackageManager (android.content.pm.IPackageManager)5 PackageInfo (android.content.pm.PackageInfo)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5