title: Listening WIFI state
body: <p>I want to set listener to listen on wireless state,can anyone help me with my code</p>
  
  <pre><code>import android.telephony.PhoneStateListener;
  import android.telephony.TelephonyManager;
  </code></pre>
  
  <p>...</p>
  
  <pre><code> TelephonyManager wTelephonyManager;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>     wTelephonyManager=(TelephonyManager)getSystemService(Context.WIFI_SERVICE);
      wTelephonyManager.listen(new PhoneL(),PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
      connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
  </code></pre>
  
  <p>//here is the event that i use that i want to listen for wifi change, and the above code is all in onCreate{} </p>
  
  <pre><code>class PhoneL extends PhoneStateListener
  
  {   
  
  
  
  
  
  
      public void onWifiStateChanged(int state, String nesto)
      {
           mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
              //mWifi.isConnectedOrConnecting()
               if(mWifi.isConnectedOrConnecting())
               {
                   Toast.makeText(WifiActivity.this,"Ima WIFI",Toast.LENGTH_LONG).show();     
               }
               else
               {
                   Toast.makeText(WifiActivity.this,"! NEMA WIFI",Toast.LENGTH_LONG).show(); 
               }
  
  
      }
  
  }
  </code></pre>
  
  <p>//Can anyone please help me creating a listener that will listen to the wifi state and check if wifi is connected or connecting if is not i want to enable data packet traffic through 3g/4g</p>