美文网首页
监控网络状态的变化

监控网络状态的变化

作者: fsdffdaga | 来源:发表于2020-06-06 20:59 被阅读0次
    
            IntentFilter filter = new IntentFilter();
            filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    
            ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo info = connectivityManager.getActiveNetworkInfo();
            Log.d("hbh", "onReceive: ================ net receive");
            if (info != null && info.isAvailable()) {
                int netType = info.getType();
                if (netType == ConnectivityManager.TYPE_WIFI) {
                    int downCount = SharedPrefUtils.getInstance(context).getInt(Constants.DOWNLOAD_COUNT);
                    String updateStatus = SharedPrefUtils.getInstance(context).getString(Constants.UPDATE_STATUS);
                    Log.i("hbh", "onReceive connection wifi, has downCount = " + downCount + ", updateStaus = " + updateStatus);
                    if (Constants.UPDATE_STATUS_DOWNING.equals(updateStatus) && (downCount >= 4 && downCount <= 6)) {
                    }
                } else if (netType == ConnectivityManager.TYPE_MOBILE) {
                    Log.i("hbh", "onReceive connection mobile data");
                }
            } else {
                Log.e("hbh", "onReceive: no net");
            }
    

    相关文章

      网友评论

          本文标题:监控网络状态的变化

          本文链接:https://www.haomeiwen.com/subject/bkpftktx.html