Android(安卓)Connectivity分析(1)- ConnectivityManager
16lz
2021-01-26
ConnectivityManager
1.描述
负责监听网络连接的状态,并发送状态变化的广播。想应用提供一些控制接口
作为ConnectivityService的一层包装,实际功能实现在ConnectivityService中。
2.类结构分析
常量定义
- intent相关
- network type定义
静态工具方法
public static String getNetworkTypeName(int type) #根据type返回名称public static boolean isNetworkTypeMobile(int networkType) #判断是否是mobile type
public static boolean isNetworkTypeValid(int networkType)
Network状态获取接口
public void setNetworkPreference(int preference) # 设置network连接优先级,preference为network type常量public int getNetworkPreference()
public NetworkInfo getActiveNetworkInfo() #获取当前激活状态的NetworkInfo
public NetworkInfo getActiveNetworkInfoForUid(int uid) #根据uid获取
public NetworkInfo getNetworkInfo(int networkType) #根据network type
NetworkInfo[] getAllNetworkInfo() #获取所有的
public LinkProperties getActiveLinkProperties() #获取当前激活状态的LinkProperties
public LinkProperties getLinkProperties(int networkType) #根据network type 获取
public NetworkQuotaInfo getActiveNetworkQuotaInfo()#获取NetworkQuotaInfo信息
public boolean getMobileDataEnabled() #获取mobile的data连接状况
public String[] getTetherableIfaces() #获取可共享iface列表
public String[] getTetheredIfaces() #获取共享的iface列表 public String[] getTetheringErroredIfaces() #获取共享error的列表
public boolean isTetheringSupported() #检测是否支持共享
public int getLastTetherError(String iface) #获取共享error
public String[] getTetherableUsbRegexs() #获取usb共享规则???(未知)
public String[] getTetherableWifiRegexs()
public String[] getTetherableBluetoothRegexs()
public boolean isNetworkSupported(int networkType) #判断硬件是否支持这类network
public boolean isActiveNetworkMetered()
功能控制接口
public boolean setRadios(boolean turnOn) #设置所有radio的开关public boolean setRadio(int networkType, boolean turnOn) #设置某个network type的radio开关
public int startUsingNetworkFeature(int networkType, String feature) #请求某个feature???(未知)
public int stopUsingNetworkFeature(int networkType, String feature)#
public boolean requestRouteToHost(int networkType, int hostAddress)#测试network type到某个address的路由是否是通路
public void setMobileDataEnabled(boolean enabled) #设置mobile的data连接开关
public int tether(String iface) #连接iface共享
public int untether(String iface) #解除共享iface
public int setUsbTethering(boolean enable) #控制usb共享
更多相关文章
- Android(安卓)获取、移除 View 的 OnClickListener
- Android中获取应用程序(包)的大小-----PackageManager的使用(二)
- Android(安卓)Http访问网络 学习(慕课网学习)
- Android应用请求获取Root权限
- Android之如何获取网络类型并判断是否可用
- Android基本功:支持GPS的核心API
- 获取应用程序中的Activity,Service等
- android监听网络状态,实时更新网络状态
- ubuntu下SVN树冲突的解决方法