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;
}