您的位置:首页 > 理论基础 > 计算机网络

获取网络连接的实例

2015-09-17 16:27 696 查看
1.在manifest文件中获取访问网络状态的权限

2.获取网络连接的工具类

int type = 0;
ConnectivityManager connectivitymanager = (ConnectivityManager) context
.getSystemService(context.CONNECTIVITY_SERVICE);
NetworkInfo netinfo = connectivitymanager.getActiveNetworkInfo();

if (netinfo == null) {
return type;
}
if (netinfo.getType() == ConnectivityManager.TYPE_MOBILE) {
type = 1;
}
if (netinfo.getType() == ConnectivityManager.TYPE_WIFI) {
type = 2;
}


具体的请看demo
http://download.csdn.net/detail/mace_android/9118291
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android