前言
此博客建设中,待后续完善。。。。
监听网络状态
ConnectivityManager connectivity = (ConnectivityManager) getContext().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkRequest.Builder builder = new NetworkRequest.Builder(); NetworkRequest request = builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) .addTransportType(NetworkCapabilities.TRANSPORT_WIFI) .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR) .build(); connectivity.registerNetworkCallback(request, new ConnectivityManager.NetworkCallback(){ @Override public void onAvailable(Network network) { super.onAvailable(network); } });