I want to develop an android app that triggers Wifi..

When we open the app, if our Wifi is on, it will toast Connected Message
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.

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..

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.

I want to introduce automation in my app. My sir gave me hint that there is some helper class in android which keep on calling the method or some event handler that handles the event that occurs outside the app, but I still have no idea how to do that.

Please help me, thanks!

Here is the java code of my app:

public class MainActivity extends ActionBarActivity implements OnClickListener {
WifiManager wf;
static Button buttn;

protected void onCreate(Bundle savedInstanceState) {
buttn = (Button) findViewById(R.id.button);
wf = (WifiManager) getSystemService(Context.WIFI_SERVICE);

public void onClick(View v) {
if (v == buttn) {
Toast.makeText(this, "Wifi Connected", Toast.LENGTH_LONG).show();

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;

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;