title: how to detect internet connection in android studio
body: <p>I have following code to detect if there is internet connection available or not. But if I have no internet connection only the data connection is "ON" it still works. what I should do?</p>
  
  <pre><code>   ConnectivityManager cManager = (ConnectivityManager) getSystemService(this.CONNECTIVITY_SERVICE);
  
  
      NetworkInfo ninfo = cManager.getActiveNetworkInfo();
  
  
      if(ninfo!=null &amp;&amp; ninfo.isConnected())
  
      {
        Toast.makeText(this, "Available",Toast.LENGTH_LONG).show();
      }
  
      else
      {
        Toast.makeText(this, "Not Available",Toast.LENGTH_LONG).show();
      }
  </code></pre>