title: Android app for Wifi automation
body: <p>I want to develop an android app that triggers Wifi..</p>
  
  <p>When we open the app, if our Wifi is on, it will toast Connected Message<br> Else, a button having a text connect will be displayed and
  when you click that button, button text will change to connected and your Wifi is turned on.</p>
  
  <p>I have done this .. but 
  my sir asked me to introduce such change that once we press button it changes from connect to connected and Wifi is on..</p>
  
  <p>Now, if we manually turn off the Wifi in our setting and then we open our paused app, then the button will show connect option again.</p>
  
  <p>I want to introduce automation in my app. My sir gave me hint that there is some <strong>helper class in android which keep on calling the method</strong> or <strong>some event handler that handles the event that occurs outside the app</strong>, but I still have no idea how to do that.</p>
  
  <p>Please help me, thanks!</p>
  
  <p>Here is the java code of my app:</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity implements OnClickListener {
      WifiManager wf;
      static Button buttn;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          buttn = (Button) findViewById(R.id.button);
          buttn.setOnClickListener(this);
          wf = (WifiManager) getSystemService(Context.WIFI_SERVICE);
      }
  
      public void onClick(View v) {
          if (v == buttn) {
              wf.setWifiEnabled(true);
              buttn.setText("connected");
              Toast.makeText(this, "Wifi Connected", Toast.LENGTH_LONG).show();
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
          // noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>