Android 代码判断是否有网络

    public void okGo() {

        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isAvailable()) {
             Toast.makeText(RadarActivity.this, "当前网络可用", Toast.LENGTH_SHORT).show();

          
        } else {
             Toast.makeText(RadarActivity.this, "当前网络不可用", Toast.LENGTH_SHORT).show();
        }


    }

 

posted @ 2018-11-19 14:42  monkey0928  阅读(1311)  评论(0编辑  收藏  举报