本文整理汇总了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);
}
示例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()]);
}
示例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()]);
}