public static boolean is(Context context){
if(context!=null){
ConnectivityManager manager= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = manager.getActiveNetworkInfo();
if(info!=null){
return info.isAvailable();
}
}
return false;
}
在Main页面里判断有网没网
if(HttpUtils.ss(this)){
Toast.makeText(this, “有网”, Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(this, “没网”, Toast.LENGTH_SHORT).show();
}
网络判断
最新推荐文章于 2023-12-22 14:05:22 发布