當前位置: 首頁>>代碼示例>>Java>>正文


Java Network.equals方法代碼示例

本文整理匯總了Java中android.net.Network.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java Network.equals方法的具體用法?Java Network.equals怎麽用?Java Network.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.net.Network的用法示例。


在下文中一共展示了Network.equals方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAllNetworksFiltered

import android.net.Network; //導入方法依賴的package包/類
/**
 * Returns all connected networks that are useful and accessible to Chrome.
 * Only callable on Lollipop and newer releases.
 * @param ignoreNetwork ignore this network as if it is not connected.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Network[] getAllNetworksFiltered(
        ConnectivityManagerDelegate connectivityManagerDelegate, Network ignoreNetwork) {
    Network[] networks = connectivityManagerDelegate.getAllNetworksUnfiltered();
    // Whittle down |networks| into just the list of networks useful to us.
    int filteredIndex = 0;
    for (Network network : networks) {
        if (network.equals(ignoreNetwork)) {
            continue;
        }
        final NetworkCapabilities capabilities =
                connectivityManagerDelegate.getNetworkCapabilities(network);
        if (capabilities == null || !capabilities.hasCapability(NET_CAPABILITY_INTERNET)) {
            continue;
        }
        if (capabilities.hasTransport(TRANSPORT_VPN)) {
            // If we can access the VPN then...
            if (connectivityManagerDelegate.vpnAccessible(network)) {
                // ...we cannot access any other network, so return just the VPN.
                return new Network[] {network};
            } else {
                // ...otherwise ignore it as we cannot use it.
                continue;
            }
        }
        networks[filteredIndex++] = network;
    }
    return Arrays.copyOf(networks, filteredIndex);
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:35,代碼來源:NetworkChangeNotifierAutoDetect.java

示例2: getDnsServerAddresses

import android.net.Network; //導入方法依賴的package包/類
@Override
@TargetApi(21)
public String[] getDnsServerAddresses() {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    Network[] networks = connectivityManager == null ? null : connectivityManager.getAllNetworks();
    if (networks == null) {
        return new String[0];
    }
    final Network activeNetwork = getActiveNetwork(connectivityManager);
    List<String> servers = new ArrayList<>();
    int vpnOffset = 0;
    for (Network network : networks) {
        LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
        if (linkProperties == null) {
            continue;
        }
        NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
        final boolean isActiveNetwork = network.equals(activeNetwork);
        if (networkInfo != null && isActiveNetwork && networkInfo.getType() == ConnectivityManager.TYPE_VPN) {
            final List<String> tmp = getIPv4First(linkProperties.getDnsServers());
            servers.addAll(0, tmp);
            vpnOffset += tmp.size();
        } else if (hasDefaultRoute(linkProperties) || isActiveNetwork) {
            servers.addAll(vpnOffset, getIPv4First(linkProperties.getDnsServers()));
        } else {
            servers.addAll(getIPv4First(linkProperties.getDnsServers()));
        }
    }
    return servers.toArray(new String[servers.size()]);
}
 
開發者ID:kriztan,項目名稱:Pix-Art-Messenger,代碼行數:31,代碼來源:AndroidUsingLinkProperties.java

示例3: getDnsServerAddresses

import android.net.Network; //導入方法依賴的package包/類
@Override
@TargetApi(21)
public String[] getDnsServerAddresses() {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    Network[] networks = connectivityManager == null ? null : connectivityManager.getAllNetworks();
    if (networks == null) {
        return new String[0];
    }
    final Network activeNetwork = getActiveNetwork(connectivityManager);
    List<String> servers = new ArrayList<>();
    int vpnOffset = 0;
    for(Network network : networks) {
        LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
        if (linkProperties == null) {
            continue;
        }
        NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
        final boolean isActiveNetwork = network.equals(activeNetwork);
        if (networkInfo != null && isActiveNetwork && networkInfo.getType() == ConnectivityManager.TYPE_VPN) {
            final List<String> tmp = getIPv4First(linkProperties.getDnsServers());
            servers.addAll(0, tmp);
            vpnOffset += tmp.size();
        } else if (hasDefaultRoute(linkProperties) || isActiveNetwork) {
            servers.addAll(vpnOffset, getIPv4First(linkProperties.getDnsServers()));
        } else {
            servers.addAll(getIPv4First(linkProperties.getDnsServers()));
        }
    }
    return servers.toArray(new String[servers.size()]);
}
 
開發者ID:siacs,項目名稱:Conversations,代碼行數:31,代碼來源:AndroidUsingLinkProperties.java


注:本文中的android.net.Network.equals方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。