当前位置: 首页>>代码示例>>Java>>正文


Java ConnectivityManager.getLinkProperties方法代码示例

本文整理汇总了Java中android.net.ConnectivityManager.getLinkProperties方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectivityManager.getLinkProperties方法的具体用法?Java ConnectivityManager.getLinkProperties怎么用?Java ConnectivityManager.getLinkProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.net.ConnectivityManager的用法示例。


在下文中一共展示了ConnectivityManager.getLinkProperties方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDnsServers

import android.net.ConnectivityManager; //导入方法依赖的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.ConnectivityManager; //导入方法依赖的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: getLP

import android.net.ConnectivityManager; //导入方法依赖的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

示例4: getDefaultDNS

import android.net.ConnectivityManager; //导入方法依赖的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


注:本文中的android.net.ConnectivityManager.getLinkProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。