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


Java ConnectivityManager.getNetworkCapabilities方法代码示例

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


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

示例1: hasInternetConnection

import android.net.ConnectivityManager; //导入方法依赖的package包/类
/**
 * @param context the current application context
 * @return whether the device was connected to the internet
 */
public static boolean hasInternetConnection(Context context) {

    /*
    Taken from Johan's answer at: https://stackoverflow.com/a/35009615
     */

    ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
    Network network;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        network = connectivityManager.getActiveNetwork();
    } else
        return true;
    NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network);
    return capabilities != null && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
}
 
开发者ID:CMPUT301F17T15,项目名称:CIA,代码行数:20,代码来源:NetworkUtilities.java

示例2: 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

示例3: getCapabilities

import android.net.ConnectivityManager; //导入方法依赖的package包/类
@RequiresApi(LOLLIPOP)
@Nullable
static NetworkCapabilities getCapabilities(@NonNull Network network,
    @NonNull ConnectivityManager connectivityManager) {

  NetworkCapabilities networkCapabilities = null;

  try {
    networkCapabilities = connectivityManager.getNetworkCapabilities(network);
  } catch (Exception exc) {
    logger.log(WARNING,
        "Could not retrieve network capabilities from provided network: " + exc.getMessage());
  }

  return networkCapabilities;
}
 
开发者ID:greyfoxit,项目名称:RxNetwork,代码行数:17,代码来源:RxNetworkInfo.java


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