获取网络连接的实例

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

猜你喜欢

转载自blog.csdn.net/mace_android/article/details/48523549
今日推荐