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


Java NetworkCapabilities.hasCapability方法代码示例

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


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

示例1: hasInternetConnection

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

import android.net.NetworkCapabilities; //导入方法依赖的package包/类
/**
 * Returns true if the system's captive portal probe was blocked for the current default data
 * network. The method will return false if the captive portal probe was not blocked, the login
 * process to the captive portal has been successfully completed, or if the captive portal
 * status can't be determined. Requires ACCESS_NETWORK_STATE permission. Only available on
 * Android Marshmallow and later versions. Returns false on earlier versions.
 */
@TargetApi(Build.VERSION_CODES.M)
@CalledByNative
private static boolean getIsCaptivePortal() {
    // NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL is only available on Marshmallow and
    // later versions.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
    ConnectivityManager connectivityManager =
            (ConnectivityManager) ContextUtils.getApplicationContext().getSystemService(
                    Context.CONNECTIVITY_SERVICE);
    if (connectivityManager == null) return false;

    Network network = connectivityManager.getActiveNetwork();
    if (network == null) return false;

    NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network);
    return capabilities != null
            && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL);
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:26,代码来源:AndroidNetworkLibrary.java

示例3: getAllNetworksFiltered

import android.net.NetworkCapabilities; //导入方法依赖的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);
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:35,代码来源:NetworkChangeNotifierAutoDetect.java

示例4: hasInternetCapability

import android.net.NetworkCapabilities; //导入方法依赖的package包/类
/**
 * Returns true if {@code network} can provide Internet access. Can be used to
 * ignore specialized networks (e.g. IMS, FOTA).
 */
@SuppressLint("NewApi")
boolean hasInternetCapability(Network network) {
  if (connectivityManager == null) {
    return false;
  }
  final NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network);
  return capabilities != null
      && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:14,代码来源:NetworkMonitorAutoDetect.java

示例5: a

import android.net.NetworkCapabilities; //导入方法依赖的package包/类
@SuppressLint({"NewApi"})
public final boolean a(Network paramNetwork)
{
  NetworkCapabilities localNetworkCapabilities = this.a.getNetworkCapabilities(paramNetwork);
  return (localNetworkCapabilities != null) && (localNetworkCapabilities.hasCapability(12));
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:7,代码来源:rja.java


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