---
title: "[Android]获取网络连接状态"
author: "MyEyeOfJava"
date: "2012-11-26T15:47:41Z"
tags: []
categories: ["开源软件"]
slug: "android"
draft: false
lastmod: "2012-04-23T11:07:47Z"
id: 1495073
url: "https://myeyeofjava.iteye.com/blog/1495073"
---

```java
ConnectivityManager cm = (ConnectivityManager) mContext.getApplicationContext().getSystemService(mContext.CONNECTIVITY_SERVICE);
		NetworkInfo[] nis=cm.getAllNetworkInfo();
		for(int i=0;i<nis.length;i++){
			//Log.d("UpdateManagerTest", nis[i].getTypeName()+"---"+nis[i].getType());
			Log.d("UpdateManagerTest", nis[i].getExtraInfo());
			//cm.stopUsingNetworkFeature(nis[i].getType(), nis[i].getTypeName());
		}
		
		boolean abc=ConnectivityManager.isNetworkTypeValid(ConnectivityManager.TYPE_WIFI);
		assertTrue(abc);
		boolean bcd=ConnectivityManager.isNetworkTypeValid(ConnectivityManager.TYPE_MOBILE);
		assertTrue(bcd);
```