本文整理汇总了Java中android.net.LinkProperties类的典型用法代码示例。如果您正苦于以下问题:Java LinkProperties类的具体用法?Java LinkProperties怎么用?Java LinkProperties使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LinkProperties类属于android.net包,在下文中一共展示了LinkProperties类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getDnsServers
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(23)
private static List<InetAddress> getDnsServers(Context context) {
List<InetAddress> servers = new ArrayList<>();
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//Network[] networks = connectivityManager == null ? null : connectivityManager.getAllNetworks();
Network[] networks = connectivityManager == null ? null : new Network[]{connectivityManager.getActiveNetwork()};
if (networks == null) {
return servers;
}
for(int i = 0; i < networks.length; ++i) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(networks[i]);
if (linkProperties != null) {
servers.addAll(linkProperties.getDnsServers());
}
}
for(InetAddress server : servers) {
Log.d("dns","DNS server: " + Strings.nullToEmpty(server.getHostName()) + " (" + server.getHostAddress() + ")");
}
return servers;
}
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:23,代码来源:RMBTTask.java
示例2: findVpnNetwork
import android.net.LinkProperties; //导入依赖的package包/类
private Network findVpnNetwork() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Network[] networks = cm.getAllNetworks();
for (Network network : networks) {
LinkProperties linkProperties = cm.getLinkProperties(network);
List<LinkAddress> addresses = linkProperties.getLinkAddresses();
for (LinkAddress addr : addresses) {
if (addr.getAddress().equals(VPN_ADDRESS)) {
return network;
}
}
}
return null;
}
开发者ID:Genymobile,项目名称:gnirehtet,代码行数:15,代码来源:GnirehtetService.java
示例3: after
import android.net.LinkProperties; //导入依赖的package包/类
@Override
protected void after(XParam param) throws Throwable {
switch (mMethod) {
case getAddresses:
case getAllAddresses:
if (param.getResult() != null)
if (isRestricted(param))
param.setResult(new ArrayList<InetAddress>());
break;
case getAllLinkAddresses:
case getLinkAddresses:
if (param.getResult() != null)
if (isRestricted(param))
param.setResult(new ArrayList<LinkAddress>());
break;
case getStackedLinks:
if (param.getResult() != null)
if (isRestricted(param))
param.setResult(new ArrayList<LinkProperties>());
break;
}
}
开发者ID:ukanth,项目名称:XPrivacy,代码行数:25,代码来源:XLinkProperties.java
示例4: getDnsServers
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(21)
private static List<InetAddress> getDnsServers(Context context) {
List<InetAddress> servers = new ArrayList<>();
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network[] networks = connectivityManager == null ? null : connectivityManager.getAllNetworks();
if (networks == null) {
return getDnsServersPreLollipop();
}
for(int i = 0; i < networks.length; ++i) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(networks[i]);
if (linkProperties != null) {
servers.addAll(linkProperties.getDnsServers());
}
}
if (servers.size() > 0) {
Log.d(Config.LOGTAG,"used lollipop variant to discover dns servers in "+networks.length+" networks");
}
return servers.size() > 0 ? servers : getDnsServersPreLollipop();
}
开发者ID:xavierle,项目名称:messengerxmpp,代码行数:20,代码来源:DNSHelper.java
示例5: getDnsServers
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
@CalledByNative
private static byte[][] getDnsServers() {
ConnectivityManager connectivityManager =
(ConnectivityManager) ContextUtils.getApplicationContext().getSystemService(
Context.CONNECTIVITY_SERVICE);
if (connectivityManager == null) {
return new byte[0][0];
}
Network network = connectivityManager.getActiveNetwork();
if (network == null) {
return new byte[0][0];
}
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
if (linkProperties == null) {
return new byte[0][0];
}
List<InetAddress> dnsServersList = linkProperties.getDnsServers();
byte[][] dnsServers = new byte[dnsServersList.size()][];
for (int i = 0; i < dnsServersList.size(); i++) {
dnsServers[i] = dnsServersList.get(i).getAddress();
}
return dnsServers;
}
开发者ID:mogoweb,项目名称:365browser,代码行数:25,代码来源:AndroidNetworkLibrary.java
示例6: getActiveInterface
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
private String getActiveInterface() {
final Network network = cm.getActiveNetwork();
if (network == null) {
return null;
}
final LinkProperties linkInfo = cm.getLinkProperties(network);
if (linkInfo == null) {
return null;
}
final List<LinkAddress> linkAddress = linkInfo.getLinkAddresses();
if (linkAddress.isEmpty()) {
return null;
}
final InetAddress address = linkAddress.get(0).getAddress();
return address.getHostAddress();
}
开发者ID:chdir,项目名称:aria2-android,代码行数:25,代码来源:ConfigBuilder.java
示例7: getDnsServers
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(21)
private static List<InetAddress> getDnsServers(Context context) {
List<InetAddress> servers = new ArrayList<>();
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network[] networks = connectivityManager == null ? null : connectivityManager.getAllNetworks();
if (networks == null) {
return getDnsServersPreLollipop();
}
for(int i = 0; i < networks.length; ++i) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(networks[i]);
if (linkProperties != null) {
if (hasDefaultRoute(linkProperties)) {
servers.addAll(0, linkProperties.getDnsServers());
} else {
servers.addAll(linkProperties.getDnsServers());
}
}
}
if (servers.size() > 0) {
Log.d(Config.LOGTAG, "used lollipop variant to discover dns servers in " + networks.length + " networks");
}
return servers.size() > 0 ? servers : getDnsServersPreLollipop();
}
开发者ID:Frozenbox,项目名称:frozenchat,代码行数:24,代码来源:DNSHelper.java
示例8: getIp
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private String getIp(LinkProperties lp) {
List<LinkAddress> las = lp.getLinkAddresses();
for(LinkAddress la: las) {
InetAddress inetAddress = la.getAddress();
if (inetAddress instanceof Inet4Address) {
//Log.d(TAG, lp.getInterfaceName() + ": " + inetAddress.getHostAddress());
return inetAddress.getHostAddress();
}
}
return null;
}
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:13,代码来源:SambaDiscovery.java
示例9: getLP
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private LinkProperties getLP(ConnectivityManager connMgr, int cap) {
Network nets[] = connMgr.getAllNetworks();
for (Network n: nets) {
LinkProperties lp = connMgr.getLinkProperties(n);
NetworkCapabilities np = connMgr.getNetworkCapabilities(n);
String iname = lp.getInterfaceName();
if (iname != null && np != null) {
//Log.d(TAG, ">>> " + iname + ": " + np.hasTransport(cap));
if (np.hasTransport(cap))
return lp;
}
}
return null;
}
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:16,代码来源:SambaDiscovery.java
示例10: getDefaultDNS
import android.net.LinkProperties; //导入依赖的package包/类
public static List<String> getDefaultDNS(Context context) {
String dns1 = null;
String dns2 = null;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network an = cm.getActiveNetwork();
if (an != null) {
LinkProperties lp = cm.getLinkProperties(an);
if (lp != null) {
List<InetAddress> dns = lp.getDnsServers();
if (dns != null) {
if (dns.size() > 0)
dns1 = dns.get(0).getHostAddress();
if (dns.size() > 1)
dns2 = dns.get(1).getHostAddress();
for (InetAddress d : dns)
Log.i(TAG, "DNS from LP: " + d.getHostAddress());
}
}
}
} else {
dns1 = jni_getprop("net.dns1");
dns2 = jni_getprop("net.dns2");
}
List<String> listDns = new ArrayList<>();
listDns.add(TextUtils.isEmpty(dns1) ? "8.8.8.8" : dns1);
listDns.add(TextUtils.isEmpty(dns2) ? "8.8.4.4" : dns2);
return listDns;
}
开发者ID:miankai,项目名称:MKAPP,代码行数:31,代码来源:Util.java
示例11: onLinkPropertiesChanged
import android.net.LinkProperties; //导入依赖的package包/类
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
super.onLinkPropertiesChanged(network, linkProperties);
if (!linkProperties.toString().equals(mLastLinkProperties)) {
mLastLinkProperties = linkProperties.toString();
VpnStatus.logDebug(String.format("Linkproperties of %s: %s", network, linkProperties));
}
}
开发者ID:akashdeepsingh9988,项目名称:Cybernet-VPN,代码行数:9,代码来源:LollipopDeviceStateListener.java
示例12: onLinkPropertiesChanged
import android.net.LinkProperties; //导入依赖的package包/类
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
// A link property change may indicate the IP address changes.
// so forward the new NetworkInformation to the observer.
Logging.d(TAG, "link properties changed: " + linkProperties.toString());
onNetworkChanged(network);
}
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:8,代码来源:NetworkMonitorAutoDetect.java
示例13: getIPAddresses
import android.net.LinkProperties; //导入依赖的package包/类
@SuppressLint("NewApi")
IPAddress[] getIPAddresses(LinkProperties linkProperties) {
IPAddress[] ipAddresses = new IPAddress[linkProperties.getLinkAddresses().size()];
int i = 0;
for (LinkAddress linkAddress : linkProperties.getLinkAddresses()) {
ipAddresses[i] = new IPAddress(linkAddress.getAddress().getAddress());
++i;
}
return ipAddresses;
}
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:11,代码来源:NetworkMonitorAutoDetect.java
示例14: getDnsServerAddresses
import android.net.LinkProperties; //导入依赖的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];
}
List<String> servers = new ArrayList<>();
int vpnOffset = 0;
for(Network network : networks) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
if (linkProperties != null) {
if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_VPN) {
final List<String> tmp = getIPv4First(linkProperties.getDnsServers());
servers.addAll(0, tmp);
vpnOffset += tmp.size();
} else if (hasDefaultRoute(linkProperties)) {
servers.addAll(vpnOffset, getIPv4First(linkProperties.getDnsServers()));
} else {
servers.addAll(getIPv4First(linkProperties.getDnsServers()));
}
}
}
return servers.toArray(new String[servers.size()]);
}
开发者ID:syntafin,项目名称:TenguChat,代码行数:28,代码来源:AndroidUsingLinkProperties.java
示例15: hasDefaultRoute
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static boolean hasDefaultRoute(LinkProperties linkProperties) {
for(RouteInfo route: linkProperties.getRoutes()) {
if (route.isDefaultRoute()) {
return true;
}
}
return false;
}
开发者ID:syntafin,项目名称:TenguChat,代码行数:10,代码来源:AndroidUsingLinkProperties.java
示例16: onLinkPropertiesChanged
import android.net.LinkProperties; //导入依赖的package包/类
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
super.onLinkPropertiesChanged(network, linkProperties);
if (!linkProperties.toString().equals(mLastLinkProperties)) {
mLastLinkProperties = linkProperties.toString();
VpnStatus.logDebug(String.format("Linkproperties of %s: %s", network, linkProperties));
}
}
开发者ID:MaxSmile,项目名称:EasyVPN-Free,代码行数:10,代码来源:LollipopDeviceStateListener.java
示例17: getDnsServerAddresses
import android.net.LinkProperties; //导入依赖的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
示例18: hasDefaultRoute
import android.net.LinkProperties; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static boolean hasDefaultRoute(LinkProperties linkProperties) {
for (RouteInfo route : linkProperties.getRoutes()) {
if (route.isDefaultRoute()) {
return true;
}
}
return false;
}
开发者ID:kriztan,项目名称:Pix-Art-Messenger,代码行数:10,代码来源:AndroidUsingLinkProperties.java
示例19: getDefaultDNS
import android.net.LinkProperties; //导入依赖的package包/类
public static List<String> getDefaultDNS(Context context) {
String dns1 = null;
String dns2 = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network an = cm.getActiveNetwork();
if (an != null) {
LinkProperties lp = cm.getLinkProperties(an);
if (lp != null) {
List<InetAddress> dns = lp.getDnsServers();
if (dns != null) {
if (dns.size() > 0)
dns1 = dns.get(0).getHostAddress();
if (dns.size() > 1)
dns2 = dns.get(1).getHostAddress();
for (InetAddress d : dns)
Log.i(TAG, "DNS from LP: " + d.getHostAddress());
}
}
}
} else {
dns1 = jni_getprop("net.dns1");
dns2 = jni_getprop("net.dns2");
}
List<String> listDns = new ArrayList<>();
listDns.add(TextUtils.isEmpty(dns1) ? "8.8.8.8" : dns1);
listDns.add(TextUtils.isEmpty(dns2) ? "8.8.4.4" : dns2);
return listDns;
}
开发者ID:M66B,项目名称:NetGuard,代码行数:31,代码来源:Util.java
示例20: showIpConfigFields
import android.net.LinkProperties; //导入依赖的package包/类
@SuppressLint("NewApi")
private void showIpConfigFields() {
WifiConfiguration config = null;
mView.findViewById(R.id.ip_fields).setVisibility(View.VISIBLE);
if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID) {
config = mAccessPoint.getConfig();
}
if (mIpSettingsSpinner.getSelectedItemPosition() == STATIC_IP) {
mView.findViewById(R.id.staticip).setVisibility(View.VISIBLE);
if (mIpAddressView == null) {
mIpAddressView = (TextView) mView.findViewById(R.id.ipaddress);
mIpAddressView.addTextChangedListener(this);
mGatewayView = (TextView) mView.findViewById(R.id.gateway);
mGatewayView.addTextChangedListener(this);
mNetworkPrefixLengthView = (TextView) mView.findViewById(
R.id.network_prefix_length);
mNetworkPrefixLengthView.addTextChangedListener(this);
mDns1View = (TextView) mView.findViewById(R.id.dns1);
mDns1View.addTextChangedListener(this);
mDns2View = (TextView) mView.findViewById(R.id.dns2);
mDns2View.addTextChangedListener(this);
}
if (config != null) {
LinkProperties linkProperties = config.linkProperties;
Iterator<LinkAddress> iterator = linkProperties.getLinkAddresses().iterator();
if (iterator.hasNext()) {
LinkAddress linkAddress = iterator.next();
mIpAddressView.setText(linkAddress.getAddress().getHostAddress());
mNetworkPrefixLengthView.setText(Integer.toString(linkAddress
.getNetworkPrefixLength()));
}
for (RouteInfo route : linkProperties.getRoutes()) {
if (route.isDefaultRoute()) {
mGatewayView.setText(route.getGateway().getHostAddress());
break;
}
}
Iterator<InetAddress> dnsIterator = linkProperties.getDnses().iterator();
if (dnsIterator.hasNext()) {
mDns1View.setText(dnsIterator.next().getHostAddress());
}
if (dnsIterator.hasNext()) {
mDns2View.setText(dnsIterator.next().getHostAddress());
}
}
} else {
mView.findViewById(R.id.staticip).setVisibility(View.GONE);
}
}
开发者ID:voyagewu,项目名称:AndroidSettingDemoAP,代码行数:55,代码来源:WifiConfigController.java
注:本文中的android.net.LinkProperties类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论