title: ANDROID: if WiFi is enabled AND active, launch an intent
body: <p>This is what I would like to do :</p>
  
  <p>=> IF WiFi is enabled AND active, launch an intent (in fact it's a WebView that gets its content=>the instructions of my app on the web)</p>
  
  <p>=> IF NOT, then I would launch another intent so that I don't show a WebView with "Web page not available ... The Web page at <a href="http://www.mywebsite.com" rel="noreferrer">http://www.mywebsite.com</a> might be temporarily down or it may have moved ..." </p>
  
  <p>I tought initially to use </p>
  
  <p>if(wifi.isWifiEnabled())</p>
  
  <p>but that does not say if the Wifi connection is ACTIVE or not. It says only that the user has turned the switch on. The device may or may not be connected... Is this correct ?</p>
  
  <p>Then I tried to use :</p>
  
  <p>if (wifi.getConnectionInfo().getSSID()!= null)</p>
  
  <p>but I noticed that it returns a string even if the connection has been lost or has been disabled ... ?</p>
  
  <p>How should I do then ?</p>
  
  <pre><code>wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
  Intent intent_instructions;
  
              if (wifi.getConnectionInfo().getSSID()!= null){
                  Log.i("Hub", "WiFi is enabled AND active !");
                  Log.i("Hub", "SSID = "+wifi.getConnectionInfo().getSSID());
                  intent_instructions = new Intent(this, Instructions.class);
              }else{
                  Log.i("Hub", "NO WiFi");
                  intent_instructions = new Intent(this, Instructions_No_WiFi.class);
              }
              this.startActivity(intent_instructions);
  </code></pre>
  
  <p>Is there a more general way to test if the device has the connectivity to the internet just before launching an intent ? be it through Wifi, 3G, etc ...</p>
  
  <p>Thanks in advance for your help.</p>