Example usage for android.net NetworkInfo getType

List of usage examples for android.net NetworkInfo getType

Introduction

In this page you can find the example usage for android.net NetworkInfo getType.

Prototype

@Deprecated
public int getType() 

Source Link

Document

Reports the type of network to which the info in this NetworkInfo pertains.

Usage

From source file:com.kaixin.connect.Util.java

/**
 * Httpapn/*from  ww w . jav  a  2  s. c  om*/
 * 
 * @throws IOException
 */
public static HttpURLConnection getConnection(Context context, URL url) throws IOException {

    // WIFIWIFI
    HttpsURLConnection httpsURLConn = null;

    // 
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connMgr.getActiveNetworkInfo();

    // WIFI
    if (null != netInfo && ConnectivityManager.TYPE_WIFI == netInfo.getType()) {
        httpsURLConn = (HttpsURLConnection) url.openConnection();
    } else {// WIFI
        String proxyHost = android.net.Proxy.getDefaultHost();

        if (null == proxyHost) { // 
            httpsURLConn = (HttpsURLConnection) url.openConnection();
        } else { // 
            java.net.Proxy p = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress(
                    android.net.Proxy.getDefaultHost(), android.net.Proxy.getDefaultPort()));
            httpsURLConn = (HttpsURLConnection) url.openConnection(p);
        }
    }
    return httpsURLConn;
}

From source file:cn.bidaround.ytcore.kaixin.KaixinUtil.java

/**
 * Httpapn??????/*from  w  ww . ja  v  a 2  s  . c o m*/
 * 
 * @throws IOException
 */
@SuppressWarnings("deprecation")
public static HttpURLConnection getConnection(Context context, URL url) throws IOException {

    // ?WIFI?WIFI??
    HttpsURLConnection httpsURLConn = null;

    // ????
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connMgr.getActiveNetworkInfo();

    // ?WIFI
    if (null != netInfo && ConnectivityManager.TYPE_WIFI == netInfo.getType()) {
        httpsURLConn = (HttpsURLConnection) url.openConnection();
    } else {// ?WIFI?
        String proxyHost = android.net.Proxy.getDefaultHost();

        if (null == proxyHost) { // ?
            httpsURLConn = (HttpsURLConnection) url.openConnection();
        } else { // ??
            java.net.Proxy p = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress(
                    android.net.Proxy.getDefaultHost(), android.net.Proxy.getDefaultPort()));
            httpsURLConn = (HttpsURLConnection) url.openConnection(p);
        }
    }
    return httpsURLConn;
}

From source file:com.ds.kaixin.Util.java

/**
 * Httpapn//from w ww  .j av a2  s .c  om
 * 
 * @throws IOException
 */
public static HttpURLConnection getConnection(Context context, URL url) throws IOException {

    // WIFIWIFI
    HttpsURLConnection httpsURLConn = null;

    // 
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connMgr.getActiveNetworkInfo();

    // WIFI
    if (null != netInfo && ConnectivityManager.TYPE_WIFI == netInfo.getType()) {
        httpsURLConn = (HttpsURLConnection) url.openConnection();
    } else {// WIFI
        String proxyHost = android.net.Proxy.getDefaultHost();

        if (null == proxyHost) { // 
            httpsURLConn = (HttpsURLConnection) url.openConnection();
        } else { // 
            java.net.Proxy p = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress(
                    android.net.Proxy.getDefaultHost(), android.net.Proxy.getDefaultPort()));
            httpsURLConn = (HttpsURLConnection) url.openConnection(p);
        }
    }
    return httpsURLConn;
}

From source file:org.basdroid.common.NetworkUtils.java

public static boolean isLTE(Context context) {
    NetworkInfo info = getNetworkInfo(context);
    if (info == null || !info.isConnected()) {
        return false;
    }/*from  ww w  .j av a  2  s.  co  m*/

    int type = info.getType();
    int subType = info.getSubtype();

    if (type == ConnectivityManager.TYPE_WIFI) {
        return false;
    } else if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return false; // ~ 50-100 kbps
        /*
         * Above API level 7, make sure to set android:targetSdkVersion
         * to appropriate level to use these
         */
        case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
        case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
        case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
        case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
            return true; // ~ 10+ Mbps
        // Unknown
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        default:
            return false;
        }
    } else {
        return false;
    }
}

From source file:org.ttrssreader.utils.Utils.java

/**
 * Only checks the connectivity without regard to the preferences
 *///from  w w  w  .  j  av  a  2 s .c  om
public static boolean checkConnected(ConnectivityManager cm, boolean onlyWifi, boolean onlyUnmeteredNetwork) {
    if (cm == null)
        return false;

    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info != null && info.isConnected()) {
        if (onlyWifi && info.getType() != ConnectivityManager.TYPE_WIFI) {
            return false;
        }
        if (onlyUnmeteredNetwork) {
            return !isNetworkMetered(cm);
        }
        return true;
    }
    return false;
}

From source file:org.ttrssreader.utils.Utils.java

public static int getNetworkType(final ConnectivityManager cm) {
    if (cm == null)
        return NETWORK_NONE;
    final NetworkInfo info = cm.getActiveNetworkInfo();
    if (info == null || !info.isConnected()) {
        return NETWORK_NONE;
    } else if (info.getType() != ConnectivityManager.TYPE_WIFI) {
        return NETWORK_MOBILE;
    } else if (isNetworkMetered(cm)) {
        return NETWORK_METERED;
    } else {// w  w  w .  j a  v  a2s .  c o  m
        return NETWORK_WIFI;
    }
}

From source file:com.tonyodev.fetch.Utils.java

static boolean isOnWiFi(Context context) {

    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();

    if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
        return activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI;
    }/*from  ww  w  .  j  a va  2  s. c  om*/

    return false;
}

From source file:org.fdroid.fdroid.UpdateService.java

/**
 * If we are to update the repos only on wifi, make sure that connection is active
 *//*  ww  w  .  j  a va 2 s . c o  m*/
private static boolean isNetworkAvailableForUpdate(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    // this could be cellular or wifi
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (activeNetwork == null) {
        return false;
    }

    if (activeNetwork.getType() != ConnectivityManager.TYPE_WIFI && Preferences.get().isUpdateOnlyOnWifi()) {
        Log.i(TAG, "Skipping update - wifi not available");
        return false;
    }
    return activeNetwork.isConnectedOrConnecting();
}

From source file:com.andrewshu.android.reddit.common.Common.java

public static boolean shouldLoadThumbnails(Activity activity, RedditSettings settings) {
    //check for wifi connection and wifi thumbnail setting
    boolean thumbOkay = true;
    if (settings.isLoadThumbnailsOnlyWifi()) {
        thumbOkay = false;//from w  w  w. j a  va2  s  .  c o  m
        ConnectivityManager connMan = (ConnectivityManager) activity
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = connMan.getActiveNetworkInfo();
        if (netInfo != null && netInfo.getType() == ConnectivityManager.TYPE_WIFI && netInfo.isConnected()) {
            thumbOkay = true;
        }
    }
    return settings.isLoadThumbnails() && thumbOkay;
}

From source file:com.appassit.common.Utils.java

/**
 * Returns whether the network is roaming
 *///from  w w w  .  j  ava 2s .  c  o m
public static boolean isNetworkRoaming(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        // Log.w(Constants.TAG, "couldn't get connectivity manager");
    } else {
        NetworkInfo info = connectivity.getActiveNetworkInfo();
        if (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE) {
        } else {
        }
    }
    return false;
}