title: How to Detect if an Android Phone have Internet Access EVEN when the Mobile Data is turn ON
body: <p>i am working on app that must have an internet connection before populating data from the server . I have a bool method that check if the there is a network connection available but it is not working properly.</p>
  
  <p><strong>Here is what is what to Achieve:</strong></p>
  
  <p>1: Check if Wifi Network is Available and there is a network Access</p>
  
  <p>2: Check is the Mobile Data is Enable and there is a Network Access</p>
  
  <p><strong>Problem(Bug) :</strong></p>
  
  <p>Currently, i do not have an internet access but my Mobile data is ON , instead of getting a Toast message that i am not connected to the internet, it will still tell me that i have an internet access but i cannot access the internet.</p>
  
  <p>I have check every other possible means but they all have an approach related to the method i am using.</p>
  
  <p><strong>QUESTION:</strong>
  How can i test if there is an Active Internet Access even if the Mobile Data is <strong>Enable</strong> .</p>
  
  <p>MY CODE:</p>
  
  <pre><code>private boolean haveConnected() {
          //Vars
          boolean wifiIsConnected = false;
          boolean mobileDataIsConnected = false;
          State checkMobile;
          State checkWifi;
          ConnectivityManager connectManager;
  
      //init  
          connectManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
          checkMobile = connectManager.getNetworkInfo(0).getState();
          checkWifi = connectManager.getNetworkInfo(1).getState();
  
          if (checkMobile == NetworkInfo.State.CONNECTED) {
              mobileDataIsConnected = true;
          } else if (checkWifi == NetworkInfo.State.CONNECTED) {
              wifiIsConnected = true;
  
          }
          return wifiIsConnected || mobileDataIsConnected;
      }
  </code></pre>