if(checkNetWorkStatus(getApplicationContext()))
{
			
  //当前网络可用
}else
{
  //当前网络不可用
  return -1;
}

 

public static boolean checkNetWorkStatus(Context context) 
{
boolean result;
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netinfo = cm.getActiveNetworkInfo();
if (netinfo != null && netinfo.isConnected()) {
result = true;
Log.i("NetStatus", "The net was connected");
} else {
result = false;
Log.i("NetStatus", "The net was bad!");
}
return result;
}

 

posted on 2012-02-01 13:28  瓦楞球  阅读(2318)  评论(0编辑  收藏  举报