PHP
·
发表于 5年以前
·
阅读量:8290
/**
* 获取ConnectivityManager
*/
public static ConnectivityManager getConnManager(Context context) {
return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
}
public static NetType getConnectedType(Context context) {
NetworkInfo net = getConnManager(context).getActiveNetworkInfo();
if (net != null) {
switch (net.getType()) {
case ConnectivityManager.TYPE_WIFI :
return NetType.Wifi;
case ConnectivityManager.TYPE_MOBILE :
return NetType.Mobile;
default :
return NetType.Other;
}
}
return NetType.None;
}