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

 

相关文章:

  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-08
  • 2021-07-24
  • 2021-12-16
猜你喜欢
  • 2021-12-22
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
  • 2022-12-23
相关资源
相似解决方案