Android Data Analyse(4)--NetworkCapabilities
来源:互联网 发布:软件定义世界 sdx 编辑:程序博客网 时间:2024/06/18 02:12
NetworkCapabilities
NetworkCapabilities 可以理解为网络能力的标识,类似于Call的Capability. 更加类似于一个工具类。
标志该网络有哪些能力,可以干些什么事,这也就决定了该类有些特定的方法。
/** * Adds the given capability to this {@code NetworkCapability} instance. * Multiple capabilities may be applied sequentially. Note that when searching * for a network to satisfy a request, all capabilities requested must be satisfied. * * @param capability the {@code NetworkCapabilities.NET_CAPABILITY_*} to be added. * @return This NetworkCapabilities instance, to facilitate chaining. * 给该network添加特定的capability */ public NetworkCapabilities addCapability(int capability) { if (capability < MIN_NET_CAPABILITY || capability > MAX_NET_CAPABILITY) { throw new IllegalArgumentException("NetworkCapability out of range"); } mNetworkCapabilities |= 1 << capability; return this; }
/** * Tests for the presence of a capabilitity on this instance. * * @param capability the {@code NetworkCapabilities.NET_CAPABILITY_*} to be tested for. * @return {@code true} if set on this instance. * 判断该网络是否拥有某种特定的网络。 */ public boolean hasCapability(int capability) { if (capability < MIN_NET_CAPABILITY || capability > MAX_NET_CAPABILITY) { return false; } return ((mNetworkCapabilities & (1 << capability)) != 0); }
常见的capabilities 有 NET_CAPABILITY_MMS , NET_CAPABILITY_SUPL ,NET_CAPABILITY_DUN 等
标志网络传输类型,说明是通过哪种方式传递的。
/** * Gets all the transports set on this {@code NetworkCapability} instance. * * @return an array of {@code NetworkCapabilities.TRANSPORT_*} values * for this instance. * 获得传输的类型 */ public int[] getTransportTypes() { return enumerateBits(mTransportTypes); }
传输的类型有:
/** * Indicates this network uses a Cellular transport. */ public static final int TRANSPORT_CELLULAR = 0; /** * Indicates this network uses a Wi-Fi transport. */ public static final int TRANSPORT_WIFI = 1; /** * Indicates this network uses a Bluetooth transport. */ public static final int TRANSPORT_BLUETOOTH = 2; /** * Indicates this network uses an Ethernet transport. */ public static final int TRANSPORT_ETHERNET = 3; /** * Indicates this network uses a VPN transport. */ public static final int TRANSPORT_VPN = 4;
NetworkCapabilities 本身没有太多功能,主要是对网络进行标识。从而供其他模块调用时判断或构建Networkrequest.
private String getImsIface() { final NetworkState[] states; try { states = mConnManager.getAllNetworkState(); } catch (RemoteException e) { Log.e(this, "getVoiceCallIfaces RemoteException" + e); return null; } if (states != null) { for (NetworkState state : states) { //判断链接的network是否有reach 运营商ims的能力 if (state.networkInfo.isConnected() && state.networkCapabilities.hasCapability( NetworkCapabilities.NET_CAPABILITY_IMS)) { final boolean isMobile = ConnectivityManager.isNetworkTypeMobile( state.networkInfo.getType()); final String baseIface = state.linkProperties.getInterfaceName(); if (isMobile) return baseIface; } } } return null; }
阅读全文
0 0
- Android Data Analyse(4)--NetworkCapabilities
- Android Data Analyse(4)--StateMachine
- Android Data Analyse(1)--ConnectivityManager
- Android Data Analyse(2)--ConnectivityService
- Android Data Analyse(3)--APN & ApnSetting & ApnContext
- android adb adbd analyse
- android adb adbd analyse
- Android Adb Analyse
- 【转】Android Adb Analyse
- Android Adb Analyse
- Android Adb Analyse
- Android Adb Analyse
- Android Adb Analyse
- Howto Analyse android process
- Android adb adbd Analyse
- Android Adb Analyse
- android adb adbd analyse
- android performance analyse
- NOIP模拟:分玩具(博弈论)
- springMVC学习笔记
- C++重载箭头操作符的理解
- 云计算,大数据,人工智能三者有何关系?
- 数据库表名不能与数据库关键字同名!
- Android Data Analyse(4)--NetworkCapabilities
- 关于建立杀不死的服务
- nodejs 基础教程--hello word
- Chrome浏览器F12开发者工具的几个小技巧总结
- C语言学习笔记(3)——指针七题
- 离线赛20171010总结
- ibatis 一对一 表连接查询
- 树入门及基本操作代码
- Python学习笔记(1)--数据类型简介