public class NetState { private Context context; public NetState(Context context) { this.context = context; } public Boolean NewWork(){ // 1.获取系统服务 ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); // 2.获取net信息 NetworkInfo info = manager.getActiveNetworkInfo(); // 3.判断网络是否可用 if (info != null&&info.isConnected()) { return true; } else { return false; } } }
网络状态判断
最新推荐文章于 2022-11-24 16:58:03 发布