本文整理匯總了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()]);
}