---
title: "android判断网络的状态断开与否"
author: "mars5337"
date: "2010-08-29T11:47:14Z"
tags: ["Android", "Mobile"]
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2010-08-29T11:47:14Z"
id: 750017
url: "https://mars5337.iteye.com/blog/750017"
---

public class ConnectionChangeReceiver extends BroadcastReceiver { @Override public void onReceive( Context context, Intent intent ) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY\_SERVICE ); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo( ConnectivityManager.TYPE\_MOBILE ); if ( activeNetInfo != null ) { Toast.makeText( context, "Active Network Type : " + activeNetInfo.getTypeName(), Toast.LENGTH\_SHORT ).show(); } if( mobNetInfo != null ) { Toast.makeText( context, "Mobile Network Type : " + mobNetInfo.getTypeName(), Toast.LENGTH\_SHORT ).show(); } } }