android.net.NetworkInfo

Here are the examples of the java api android.net.NetworkInfo taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1577 Examples 7

19 Source : PushService.java
with GNU General Public License v3.0
from zhangneng

// Check if we are online
private boolean isNetworkAvailable() {
    NetworkInfo info = mConnMan.getActiveNetworkInfo();
    if (info == null) {
        return false;
    }
    return info.isConnected();
}

19 Source : XNetworkUtils.java
with Apache License 2.0
from youth5201314

/**
 * 判断网络是否是4G
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean is4G() {
    NetworkInfo info = getActiveNetworkInfo();
    return info != null && info.isAvailable() && info.getSubtype() == TelephonyManager.NETWORK_TYPE_LTE;
}

19 Source : XNetworkUtils.java
with Apache License 2.0
from youth5201314

/**
 * 判断网络是否连接
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isConnected() {
    NetworkInfo info = getActiveNetworkInfo();
    return info != null && info.isConnected();
}

19 Source : XNetworkUtils.java
with Apache License 2.0
from youth5201314

/**
 * 判断网络是否可用
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
 *
 * @return {@code true}: 可用<br>{@code false}: 不可用
 */
public static boolean isAvailable() {
    NetworkInfo info = getActiveNetworkInfo();
    return info != null && info.isAvailable();
}

19 Source : NetworkChecker.java
with Apache License 2.0
from yanzhenjie

/**
 * Whether network connection.
 */
private static boolean isConnected(NetworkInfo networkInfo) {
    return networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected();
}

19 Source : NetworkChecker.java
with Apache License 2.0
from yanzhenjie

private static boolean isConnected(NetType netType, NetworkInfo networkInfo) {
    if (networkInfo == null)
        return false;
    switch(netType) {
        case Wifi:
            {
                if (!isConnected(networkInfo))
                    return false;
                return networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
            }
        case Wired:
            {
                if (!isConnected(networkInfo))
                    return false;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
                    return networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET;
                return false;
            }
        case Mobile:
            {
                if (!isConnected(networkInfo))
                    return false;
                return networkInfo.getType() == ConnectivityManager.TYPE_MOBILE;
            }
        case Mobile2G:
            {
                if (!isConnected(Mobile, networkInfo))
                    return false;
                return isMobileSubType(Mobile2G, networkInfo);
            }
        case Mobile3G:
            {
                if (!isConnected(Mobile, networkInfo))
                    return false;
                return isMobileSubType(Mobile3G, networkInfo);
            }
        case Mobile4G:
            {
                if (!isConnected(Mobile, networkInfo))
                    return false;
                return isMobileSubType(Mobile4G, networkInfo);
            }
    }
    return false;
}

19 Source : AppModel.java
with GNU General Public License v3.0
from XndroidDev

public static void getNetworkState() {
    if (sConnectivityManager == null) {
        sConnectivityManager = (ConnectivityManager) sContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    }
    sDevMobileWork = false;
    NetworkInfo activeNetworkInfo = sConnectivityManager.getActiveNetworkInfo();
    if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
        if (activeNetworkInfo.getType() == (ConnectivityManager.TYPE_MOBILE)) {
            sDevMobileWork = true;
        }
    }
    LogUtils.i("network change, use_mobile_network=" + sDevMobileWork);
}

19 Source : ServiceGenerator.java
with GNU General Public License v3.0
from wncc

public boolean isConnected() {
    try {
        android.net.ConnectivityManager e = (android.net.ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = e.getActiveNetworkInfo();
        return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    } catch (Exception e) {
    }
    return false;
}

19 Source : PreferencesUtility.java
with GNU General Public License v3.0
from Vinetos

public boolean loadArtistAndAlbumImages() {
    if (mPreferences.getBoolean(ARTIST_ALBUM_IMAGE, true)) {
        if (!mPreferences.getBoolean(ARTIST_ALBUM_IMAGE_MOBILE, true)) {
            if (connManager == null)
                connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo ni = connManager.getActiveNetworkInfo();
            return ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI;
        }
        return true;
    }
    return false;
}

19 Source : NetworkTracker.java
with GNU General Public License v3.0
from vbier

private void updateStatus() {
    NetworkInfo activeNetwork = cm == null ? null : cm.getActiveNetworkInfo();
    if (activeNetwork != null && activeNetwork.isConnected()) {
        Log.d(TAG, "network is active: " + activeNetwork);
        if (!mConnected) {
            synchronized (mListeners) {
                mConnected = true;
                Log.d(TAG, "notifying listeners of active network...");
                for (INetworkListener listener : mListeners) {
                    listener.connected();
                }
            }
        }
    } else {
        Log.d(TAG, "network is NOT active: " + activeNetwork);
        if (mConnected) {
            synchronized (mListeners) {
                mConnected = false;
                Log.d(TAG, "notifying listeners of inactive network...");
                for (INetworkListener listener : mListeners) {
                    listener.disconnected();
                }
            }
        }
    }
}

19 Source : RequestHandler.java
with GNU General Public License v3.0
from umerov1999

boolean shouldRetry(boolean airplaneMode, NetworkInfo info) {
    return false;
}

19 Source : Dispatcher.java
with GNU General Public License v3.0
from umerov1999

void performNetworkStateChange(NetworkInfo info) {
    if (service instanceof PicreplacedoExecutorService) {
        ((PicreplacedoExecutorService) service).adjustThreadCount(info);
    }
    // Intentionally check only if isConnected() here before we flush out failed actions.
    if (info != null && info.isConnected()) {
        flushFailedActions();
    }
}

19 Source : BitmapHunter.java
with GNU General Public License v3.0
from umerov1999

boolean shouldRetry(boolean airplaneMode, NetworkInfo info) {
    boolean hasRetries = retryCount > 0;
    if (!hasRetries) {
        return false;
    }
    retryCount--;
    return requestHandler.shouldRetry(airplaneMode, info);
}

19 Source : CheckConnection.java
with MIT License
from UdacityAndroidBasicsScholarship

/*
        Check whether connected to network or not
     */
public Boolean isConnected() {
    NetworkInfo networkInfo = getNetworkInfo();
    return networkInfo != null && networkInfo.isConnectedOrConnecting();
}

19 Source : CheckConnection.java
with MIT License
from UdacityAndroidBasicsScholarship

/*
        Check whether Connected to Mobile Data or not
     */
public Boolean isMobileConnected() {
    NetworkInfo networkInfo = getNetworkInfo();
    return networkInfo.getType() == ConnectivityManager.TYPE_MOBILE;
}

19 Source : CheckConnection.java
with MIT License
from UdacityAndroidBasicsScholarship

/*
        Check whether Connected to Wifi or not
     */
public Boolean isWifiConnected() {
    NetworkInfo networkInfo = getNetworkInfo();
    return networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
}

19 Source : UCNetworkInfo.java
with Apache License 2.0
from ucloud

/**
 * Created by joshua on 2018/9/20 15:11.
 * Company: UCloud
 * E-mail: [email protected]
 */
public clreplaced UCNetworkInfo implements JsonSerializable {

    /**
     * android系统网络信息类:{@link android.net.NetworkInfo}
     */
    private NetworkInfo sysNetInfo;

    /**
     * UNetreplacedysisSDK状态集, {@link UCNetStatus}
     */
    private UCNetStatus netStatus;

    /**
     * 信号强度 (dbm)
     */
    private int signalStrength;

    public UCNetworkInfo(NetworkInfo sysNetInfo) {
        this.sysNetInfo = sysNetInfo;
        this.netStatus = UCNetStatus.parseStatusByNetworkInfo(this.sysNetInfo);
    }

    public NetworkInfo getSysNetInfo() {
        return sysNetInfo;
    }

    public UCNetStatus getNetStatus() {
        return netStatus;
    }

    public int getSignalStrength() {
        return signalStrength;
    }

    public void setSignalStrength(int signalStrength) {
        this.signalStrength = signalStrength;
    }

    public void setSysNetInfo(NetworkInfo sysNetInfo) {
        this.sysNetInfo = sysNetInfo;
        this.netStatus = UCNetStatus.parseStatusByNetworkInfo(this.sysNetInfo);
    }

    @Override
    public String toString() {
        return toJson().toString();
    }

    @Override
    public JSONObject toJson() {
        JSONObject json = new JSONObject();
        try {
            json.put("netStatus", netStatus == null ? JSONObject.NULL : netStatus.name());
            json.put("signalStrength", signalStrength);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return json;
    }
}

19 Source : UCNetworkInfo.java
with Apache License 2.0
from ucloud

public void setSysNetInfo(NetworkInfo sysNetInfo) {
    this.sysNetInfo = sysNetInfo;
    this.netStatus = UCNetStatus.parseStatusByNetworkInfo(this.sysNetInfo);
}

19 Source : PreferencesProviderWrapper.java
with GNU General Public License v3.0
from treasure-lau

private boolean isValidAnywayConnectionFor(NetworkInfo ni, String suffix) {
    return getPreferenceBooleanValue("use_anyway_" + suffix, false);
}

19 Source : PreferencesProviderWrapper.java
with GNU General Public License v3.0
from treasure-lau

// Check for other (wimax for example)
private boolean isValidOtherConnectionFor(NetworkInfo ni, String suffix) {
    boolean valid_for_other = getPreferenceBooleanValue("use_other_" + suffix, true);
    // boolean valid_for_other = true;
    if (valid_for_other && ni != null && ni.getType() != ConnectivityManager.TYPE_MOBILE && ni.getType() != ConnectivityManager.TYPE_WIFI) {
        return ni.isConnected();
    }
    return false;
}

19 Source : PreferencesProviderWrapper.java
with GNU General Public License v3.0
from treasure-lau

/**
 * Say whether current connection is valid for incoming calls
 *
 * @return true if connection is valid
 */
public boolean isValidConnectionForIncoming() {
    NetworkInfo ni = connectivityManager.getActiveNetworkInfo();
    return isValidConnectionFor(ni, "in");
}

19 Source : PreferencesProviderWrapper.java
with GNU General Public License v3.0
from treasure-lau

// Generic function for both incoming and outgoing
private boolean isValidConnectionFor(NetworkInfo ni, String suffix) {
    if (isValidWifiConnectionFor(ni, suffix)) {
        Log.d(THIS_FILE, "We are valid for WIFI");
        return true;
    }
    if (isValidMobileConnectionFor(ni, suffix)) {
        Log.d(THIS_FILE, "We are valid for MOBILE");
        return true;
    }
    if (isValidOtherConnectionFor(ni, suffix)) {
        Log.d(THIS_FILE, "We are valid for OTHER");
        return true;
    }
    if (isValidAnywayConnectionFor(ni, suffix)) {
        Log.d(THIS_FILE, "We are valid ANYWAY");
        return true;
    }
    return false;
}

19 Source : PreferencesProviderWrapper.java
with GNU General Public License v3.0
from treasure-lau

private int getKeepAliveInterval(String wifi_key, String mobile_key) {
    NetworkInfo ni = connectivityManager.getActiveNetworkInfo();
    if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI) {
        return getPreferenceIntegerValue(wifi_key);
    }
    return getPreferenceIntegerValue(mobile_key);
}

19 Source : PreferencesProviderWrapper.java
with GNU General Public License v3.0
from treasure-lau

/**
 * Say whether current connection is valid for outgoing calls
 * @param considerQuit preplaced true if we should consider app quitted as a reason to not consider available for outgoing
 * @return true if connection is valid
 */
public boolean isValidConnectionForOutgoing(boolean considerQuit) {
    if (considerQuit) {
        if (getPreferenceBooleanValue(PreferencesWrapper.HAS_BEEN_QUIT, false)) {
            // Don't go further, we have been explicitly stopped
            return false;
        }
    }
    NetworkInfo ni = connectivityManager.getActiveNetworkInfo();
    return isValidConnectionFor(ni, "out");
}

19 Source : PreferencesProviderWrapper.java
with GNU General Public License v3.0
from treasure-lau

// Check for acceptable mobile data network connection
private boolean isValidMobileConnectionFor(NetworkInfo ni, String suffix) {
    boolean valid_for_3g = getPreferenceBooleanValue("use_3g_" + suffix, false);
    boolean valid_for_edge = getPreferenceBooleanValue("use_edge_" + suffix, false);
    boolean valid_for_gprs = getPreferenceBooleanValue("use_gprs_" + suffix, false);
    boolean valid_for_roaming = getPreferenceBooleanValue("use_roaming_" + suffix, true);
    if (!valid_for_roaming && ni != null) {
        if (ni.isRoaming()) {
            return false;
        }
    }
    if ((valid_for_3g || valid_for_edge || valid_for_gprs) && ni != null) {
        int type = ni.getType();
        // Any mobile network connected
        if (ni.isConnected() && // Type 3,4,5 are other mobile data ways
        (type == ConnectivityManager.TYPE_MOBILE || (type <= 5 && type >= 3))) {
            int subType = ni.getSubtype();
            // 3G (or better)
            if (valid_for_3g && subType >= TelephonyManager.NETWORK_TYPE_UMTS) {
                return true;
            }
            // GPRS (or unknown)
            if (valid_for_gprs && (subType == TelephonyManager.NETWORK_TYPE_GPRS || subType == TelephonyManager.NETWORK_TYPE_UNKNOWN)) {
                return true;
            }
            // EDGE
            if (valid_for_edge && subType == TelephonyManager.NETWORK_TYPE_EDGE) {
                return true;
            }
        }
    }
    return false;
}

19 Source : PreferencesProviderWrapper.java
with GNU General Public License v3.0
from treasure-lau

// Network part
// Check for wifi
private boolean isValidWifiConnectionFor(NetworkInfo ni, String suffix) {
    boolean valid_for_wifi = getPreferenceBooleanValue("use_wifi_" + suffix, true);
    // We consider ethernet as wifi
    if (valid_for_wifi && ni != null) {
        int type = ni.getType();
        // Wifi connected
        if (ni.isConnected() && // 9 = ConnectivityManager.TYPE_ETHERNET
        (type == ConnectivityManager.TYPE_WIFI || type == 9)) {
            return true;
        }
    }
    return false;
}

19 Source : NetManager.java
with Apache License 2.0
from tohodog

/*
     * WIFI是否连接
     * */
private boolean isNetworkConnected() {
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return (networkInfo != null && networkInfo.isConnected());
}

19 Source : NetworkUtils.java
with Apache License 2.0
from tianshaojie

/**
 * Return whether using mobile data.
 * <p>Must hold {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />}</p>
 *
 * @return {@code true}: yes<br>{@code false}: no
 */
@RequiresPermission(ACCESS_NETWORK_STATE)
public static boolean isMobileData() {
    NetworkInfo info = getActiveNetworkInfo();
    return null != info && info.isAvailable() && info.getType() == ConnectivityManager.TYPE_MOBILE;
}

19 Source : NetworkUtils.java
with Apache License 2.0
from tianshaojie

/**
 * Return whether using 4G.
 * <p>Must hold {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />}</p>
 *
 * @return {@code true}: yes<br>{@code false}: no
 */
@RequiresPermission(ACCESS_NETWORK_STATE)
public static boolean is4G() {
    NetworkInfo info = getActiveNetworkInfo();
    return info != null && info.isAvailable() && info.getSubtype() == TelephonyManager.NETWORK_TYPE_LTE;
}

19 Source : NetworkUtils.java
with Apache License 2.0
from tianshaojie

/**
 * Return whether network is connected.
 * <p>Must hold {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />}</p>
 *
 * @return {@code true}: connected<br>{@code false}: disconnected
 */
@RequiresPermission(ACCESS_NETWORK_STATE)
public static boolean isConnected() {
    NetworkInfo info = getActiveNetworkInfo();
    return info != null && info.isConnected();
}

19 Source : Utils.java
with GNU General Public License v3.0
from TachibanaGeneralLaboratories

public static boolean checkConnectivity(@NonNull SettingsRepository pref, @NonNull SystemFacade systemFacade) {
    NetworkInfo netInfo = systemFacade.getActiveNetworkInfo();
    return netInfo != null && netInfo.isConnected() && isNetworkTypeAllowed(pref, systemFacade);
}

19 Source : DownloadThreadImpl.java
with GNU General Public License v3.0
from TachibanaGeneralLaboratories

private void handleRetryableStatus(boolean madeProgress) {
    info.numFailed++;
    if (info.numFailed < pref.maxDownloadRetries()) {
        NetworkInfo netInfo = systemFacade.getActiveNetworkInfo();
        if (netInfo != null && netInfo.getType() == networkType && netInfo.isConnected())
            /* Underlying network is still intact, use normal backoff */
            info.statusCode = STATUS_WAITING_TO_RETRY;
        else
            /* Network changed, retry on any next available */
            info.statusCode = STATUS_WAITING_FOR_NETWORK;
        if (getETag(repo.getHeadersById(id)) == null && madeProgress) {
            /*
                 * However, if we wrote data and have no ETag to verify
                 * contents against later, we can't actually resume
                 */
            info.statusCode = STATUS_CANNOT_RESUME;
        }
    }
}

19 Source : DownloadThreadImpl.java
with GNU General Public License v3.0
from TachibanaGeneralLaboratories

@Override
public DownloadResult call() {
    running = true;
    try {
        info = repo.getInfoById(id);
        if (info == null) {
            Log.w(TAG, "Info " + id + " is null, skipping");
            return new DownloadResult(id, DownloadResult.Status.STOPPED);
        }
        if (info.statusCode == STATUS_SUCCESS) {
            Log.w(TAG, id + " already finished, skipping");
            return new DownloadResult(id, DownloadResult.Status.FINISHED);
        }
        if (!info.hasMetadata)
            info.statusCode = STATUS_FETCH_METADATA;
        else
            info.statusCode = STATUS_RUNNING;
        info.statusMsg = null;
        writeToDatabase(false);
        /*
             * Remember which network this download started on;
             * used to determine if errors were due to network changes
             */
        NetworkInfo netInfo = systemFacade.getActiveNetworkInfo();
        if (netInfo != null)
            networkType = netInfo.getType();
        ExecDownloadResult res = execDownload();
        if (res.stopRequest != null) {
            info.statusCode = res.stopRequest.getFinalStatus();
            info.statusMsg = res.stopRequest.getMessage();
            Log.i(TAG, "id=" + id + ", code=" + info.statusCode + ", msg=" + info.statusMsg);
        } else {
            info.statusCode = STATUS_SUCCESS;
        }
        checkPiecesStatus(res.pieceResultList);
    } catch (Throwable t) {
        Log.e(TAG, Log.getStackTraceString(t));
        if (info != null) {
            info.statusCode = STATUS_UNKNOWN_ERROR;
            info.statusMsg = t.getMessage();
        }
    } finally {
        finalizeThread();
    }
    DownloadResult.Status status = DownloadResult.Status.FINISHED;
    if (info != null) {
        switch(info.statusCode) {
            case STATUS_PAUSED:
                status = DownloadResult.Status.PAUSED;
                break;
            case STATUS_STOPPED:
                status = DownloadResult.Status.STOPPED;
                break;
        }
    }
    return new DownloadResult(id, status);
}

19 Source : RequestHandler.java
with GNU General Public License v3.0
from stingle

boolean shouldRetry(boolean airplaneMode, @Nullable NetworkInfo info) {
    return false;
}

19 Source : Dispatcher.java
with GNU General Public License v3.0
from stingle

void performNetworkStateChange(NetworkInfo info) {
    // Intentionally check only if isConnected() here before we flush out failed actions.
    if (info != null && info.isConnected()) {
        flushFailedActions();
    }
}

19 Source : BitmapHunter.java
with GNU General Public License v3.0
from stingle

boolean shouldRetry(boolean airplaneMode, @Nullable NetworkInfo info) {
    boolean hasRetries = retryCount > 0;
    if (!hasRetries) {
        return false;
    }
    retryCount--;
    return requestHandler.shouldRetry(airplaneMode, info);
}

19 Source : NetworkUtils.java
with Apache License 2.0
from smuyyh

/**
 * 判断网络是否连接
 * <p>需添加权限
 * {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />}</p>
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isConnected() {
    NetworkInfo info = getActiveNetworkInfo();
    return info != null && info.isConnected();
}

19 Source : NetworkUtils.java
with Apache License 2.0
from smuyyh

/**
 * 判断网络是否是移动数据
 * <p>需添加权限
 * {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />}</p>
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
@SuppressLint("MissingPermission")
public static boolean isMobileData() {
    NetworkInfo info = getActiveNetworkInfo();
    return null != info && info.isAvailable() && info.getType() == ConnectivityManager.TYPE_MOBILE;
}

19 Source : NetworkUtils.java
with Apache License 2.0
from smuyyh

/**
 * 判断网络是否是 4G
 * <p>需添加权限
 * {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />}</p>
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean is4G() {
    NetworkInfo info = getActiveNetworkInfo();
    return info != null && info.isAvailable() && info.getSubtype() == TelephonyManager.NETWORK_TYPE_LTE;
}

19 Source : NetworkUtils.java
with Apache License 2.0
from Shouheng88

@RequiresPermission(ACCESS_NETWORK_STATE)
public static boolean isMobileData() {
    NetworkInfo info = getActiveNetworkInfo();
    return null != info && info.isAvailable() && info.getType() == ConnectivityManager.TYPE_MOBILE;
}

19 Source : NetworkUtils.java
with Apache License 2.0
from Shouheng88

@RequiresPermission(ACCESS_NETWORK_STATE)
public static boolean isConnected() {
    NetworkInfo info = getActiveNetworkInfo();
    return info != null && info.isConnected();
}

19 Source : NetworkUtils.java
with Apache License 2.0
from Shouheng88

@RequiresPermission(ACCESS_NETWORK_STATE)
public static boolean is4G() {
    NetworkInfo info = getActiveNetworkInfo();
    return info != null && info.isAvailable() && info.getSubtype() == TelephonyManager.NETWORK_TYPE_LTE;
}

19 Source : DictionarySettingsFragment.java
with Apache License 2.0
from sergchil

void refreshNetworkState() {
    NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
    boolean isConnected = null == info ? false : info.isConnected();
    if (null != mUpdateNowMenu)
        mUpdateNowMenu.setEnabled(isConnected);
}

19 Source : ConnectivityHelper.java
with Apache License 2.0
from saki4510t

private void updateActiveNetwork(@Nullable final NetworkInfo activeNetworkInfo) {
    final int type = (activeNetworkInfo != null) && (activeNetworkInfo.isConnectedOrConnecting()) ? activeNetworkInfo.getType() : -1;
    int activeNetworkType = NETWORK_TYPE_NON;
    switch(type) {
        case -1:
            break;
        case ConnectivityManager.TYPE_MOBILE:
            activeNetworkType = NETWORK_TYPE_MOBILE;
            break;
        case ConnectivityManager.TYPE_WIFI:
            activeNetworkType = NETWORK_TYPE_WIFI;
            break;
        case ConnectivityManager.TYPE_ETHERNET:
            activeNetworkType = NETWORK_TYPE_ETHERNET;
            break;
    }
    updateActiveNetwork(activeNetworkType);
}

19 Source : RequestInterceptor.java
with MIT License
from raedev

private boolean isConnected() {
    NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
    return networkInfo != null && (networkInfo.isConnected() && networkInfo.isAvailable());
}

19 Source : BlogContentTask.java
with MIT License
from raedev

private boolean isWIFI() {
    NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
}

19 Source : NetworkManager.java
with MIT License
from qq283335746

/**
 * Get the latest network connection information
 *
 * @param info the current active network info
 * @return a JSONObject that represents the network info
 */
private JSONObject getConnectionInfo(NetworkInfo info) {
    String type = TYPE_NONE;
    String extraInfo = "";
    if (info != null) {
        // If we are not connected to any network set type to none
        if (!info.isConnected()) {
            type = TYPE_NONE;
        } else {
            type = getType(info);
        }
        extraInfo = info.getExtraInfo();
    }
    Log.d("CordovaNetworkManager", "Connection Type: " + type);
    Log.d("CordovaNetworkManager", "Connection Extra Info: " + extraInfo);
    JSONObject connectionInfo = new JSONObject();
    try {
        connectionInfo.put("type", type);
        connectionInfo.put("extraInfo", extraInfo);
    } catch (JSONException e) {
    }
    return connectionInfo;
}

19 Source : NetworkManager.java
with MIT License
from qq283335746

// --------------------------------------------------------------------------
// LOCAL METHODS
// --------------------------------------------------------------------------
/**
 * Updates the JavaScript side whenever the connection changes
 *
 * @param info the current active network info
 * @return
 */
private void updateConnectionInfo(NetworkInfo info) {
    // send update to javascript "navigator.network.connection"
    // Jellybean sends its own info
    JSONObject thisInfo = this.getConnectionInfo(info);
    if (!thisInfo.equals(lastInfo)) {
        String connectionType = "";
        try {
            connectionType = thisInfo.get("type").toString();
        } catch (JSONException e) {
        }
        sendUpdate(connectionType);
        lastInfo = thisInfo;
    }
}

19 Source : DNSCache.java
with Apache License 2.0
from PureDark

// ///////////////////////////////////////////////////////////////////////////////////
/**
 * 网络环境发生变化 刷新缓存数据 暂时先不需要 预处理逻辑。 用户直接请求的时候会更新数据。 (会有一次走本地dns ,
 * 后期优化这个方法,主动请求缓存的数据)
 *
 * @param networkInfo
 */
public void onNetworkStatusChanged(NetworkInfo networkInfo) {
    if (null != dnsCacheManager) {
        dnsCacheManager.clearMemoryCache();
    }
}

19 Source : DefaultBandwidthMeterTest.java
with Apache License 2.0
from PaulWoitaschek

private void setActiveNetworkInfo(NetworkInfo networkInfo) {
    Shadows.shadowOf(connectivityManager).setActiveNetworkInfo(networkInfo);
}

See More Examples