---
title: "android检查网络是否正常"
author: "happy90"
date: "2012-08-02T09:52:13Z"
tags: []
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2012-10-16T09:40:09Z"
id: 1616712
url: "https://happy90.iteye.com/blog/1616712"
---

 /**
     * 检查网络是否正常.
     * 
     * @return	true: 正常，false 不正常
     */
	public boolean checkNetwork() {
		boolean flag = false;
		ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		if (cwjManager.getActiveNetworkInfo() != null) {
			flag = cwjManager.getActiveNetworkInfo().isAvailable();
		}
		return flag;
	}