本文整理汇总了Java中android.net.LinkAddress类的典型用法代码示例。如果您正苦于以下问题:Java LinkAddress类的具体用法?Java LinkAddress怎么用?Java LinkAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LinkAddress类属于android.net包,在下文中一共展示了LinkAddress类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findVpnNetwork
import android.net.LinkAddress; //导入依赖的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;
}
示例2: after
import android.net.LinkAddress; //导入依赖的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;
}
}
示例3: getActiveInterface
import android.net.LinkAddress; //导入依赖的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();
}
示例4: getIp
import android.net.LinkAddress; //导入依赖的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;
}
示例5: getIPAddresses
import android.net.LinkAddress; //导入依赖的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;
}
示例6: showIpConfigFields
import android.net.LinkAddress; //导入依赖的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);
}
}