Just use the following method:

    public boolean isOnline() {
        boolean status=false;
        try{
            ConnectivityManager cm = 
                (ConnectivityManager) getActivity()
                        .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo netInfo = cm.getActiveNetworkInfo();
            status=netInfo.isConnected();
        }catch(Exception e){
            e.printStackTrace();
            return false;
        }
        return status;
    }

Pin It on Pinterest

Share This